`
shixiaomu
  • 浏览: 386792 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

apache axis 解析.netc# wse dataset

    博客分类:
  • java
阅读更多
package etpsmsws.etpsms.hnas;


import java.util.Iterator;

import javax.xml.namespace.QName;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.MessageElement;
import org.apache.axis.types.Schema;

/**
* <p>
* Title:
* </p>
* <p>
* Description:
* </p>
* <p>
* Copyright: Copyright (c) 2004
* </p>
* <p>
* Company:
* </p>
*
* @author not attributable
* @version 1.0
*/
public class testSoap2 {
public testSoap2() {
}

public static void main(String[] args) {
try {

String wsdlUrl = "http://test";
String soapActionURI = "HNAS.EtpSms.EtpSmsWS/GetRecvFromTemp";

Service service = new Service();
Call call = (Call) service.createCall();
//
// call.setOperationName(new QName("HNAS.EtpSms.EtpSmsWS",
// "EtpSmsWSSoap"));
call.setOperationName(new QName("HNAS.EtpSms.EtpSmsWS",
"GetRecvFromTemp"));
call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));
call.addParameter(new QName("HNAS.EtpSms.EtpSmsWS", "iMemberId"),
org.apache.axis.encoding.XMLType.XSD_INT,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_SCHEMA);
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapActionURI);

Object[] objs = new Object[] { "8918"};
Object res = call.invoke(objs);
// System.out.println(res);
Schema schema = (Schema) res;
MessageElement[] messageElement = schema.get_any();
for (int i = 0; i < messageElement.length; i++) {
// System.out.println(messageElement[i].getChildElements());
// System.out.println(messageElement[i].getRealElement()
// .getChildren());

Iterator iterator = messageElement[i].getChildElements();
while (iterator.hasNext()) {
MessageElement m = (MessageElement) iterator.next();
m = m.getRealElement();
Iterator it = m.getChildElements();
while (it.hasNext()) {
m = (MessageElement) it.next();
it = m.getChildElements();
while (it.hasNext()) {
m = (MessageElement) it.next();
System.out.println(m.getValue());
}
}
}
}

} catch (Exception ex) {
System.err.println(ex.toString());
}
}
}


注意事项:
参数必须是String类型的,你定义的是啥类型不管。
setOperationName 要给方法名。







1. 概述
  
  很多正在开发或者打算开发XML Web Services的程序员都问过这样的一个问题:"我的Web Service返回的结果是一个DataSet类型的对象,但如果我的客户端不是用.NET写的(因而没有内建的DataSet类型),

那该如何调用这个Web Service并访问DataSet中的数据呢?"。
  
  对于这个问题,首先应该说的是:1)在多种语言共存的编程环境下,是不适合使用类似DataSet这种只属于特定语言的数据类型的。不管是在XML Web Services还是CORBA的环境中,都应该尽量使用简单数据类型以及简单数据类型的数组。2)应当很谨慎的决定是否需要通过Web Service来返回大量数据。由于网络传输的开销既包括HTTP连接建立的时间,也包括传送数据的时间,因此需要在减少访问服务器次数和减少网络传输量之间寻找一个合适的平衡。如非必须,则不适合通过Web Service传送含有几十条或者几百条数据的数据表。
  
  然后,就问题本身而言,.NET Web Services返回的DataSet类型是可以直接被其他非.NET的客户端解析的,因为即便是DataSet类型的返回值,也会被表达成XML格式再进行传输。下面的例子就是一个返回类型为DataSet的Web Method,及其被调用后返回的XML格式数据:

2. 创建.NET Web Services,返回数据集合
    [WebMethod]
    public DataSet GetPersonTable(string str)
    ...{
        DataTable table = new DataTable("Person");
        table.Columns.Add("Name");
        table.Columns.Add("Gender");
        table.Rows.Add(new string[2] ...{ "Alice", "Female" });
        table.Rows.Add(new string[2] ...{ "Bob", "Male" });
        table.Rows.Add(new string[2] ...{ "Chris", "Female" });
        table.Rows.Add(new string[2] ...{ "Dennis", "Male" });
        table.Rows.Add(new string[2] ...{ "Eric", "Male" });

        DataSet dataset = new DataSet("PersonTable");
        dataset.Tables.Add(table);

        return dataset;
    }

3. 在Java中调用.NET Web Services,处理返回的数据集合
try ...{

            String wsdlUrl = "http://localhost/WebSite1/Service.asmx?op=GetPersonTable";  
            String soapActionURI = "http://tempuri.org/GetPersonTable";  

            Service service = new Service();  
            Call call = (Call) service.createCall();   
            // 
            call.setOperationName(new QName("http://tempuri.org/","GetPersonTable"));
            call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));
            call.addParameter("a", org.apache.axis.encoding.XMLType.XSD_STRING,  
                    javax.xml.rpc.ParameterMode.IN);
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_SCHEMA);  
            call.setUseSOAPAction(true);  
            call.setSOAPActionURI(soapActionURI);
           
            Object[] objs = new Object[]...{"ssss"};
            Object res = call.invoke( objs );
            System.out.println(res);
            Schema schema = (Schema)res;
                    
            DefaultTableModel model=new  DefaultTableModel(new String[]...{"name","gender"},0);
            schema.get_any()[1].getChildNodes().getLength();
            int nLength=schema.get_any()[1].getChildNodes().item(0).getChildNodes().getLength();
            String name="N/A";
            String gender="N/A";
            for(int i=0;i<nLength;i++)
            ...{
                if(schema.get_any()[1].getChildNodes().item(0).getChildNodes().item(i).getChildNodes().item(0).getNodeName().equals("Name"))
                ...{
                    name=schema.get_any()[1].getChildNodes().item(0).getChildNodes().item(i).getChildNodes().item(0).getFirstChild().getNodeValue();
                }
                if(schema.get_any()[1].getChildNodes().item(0).getChildNodes().item(i).getChildNodes().item(1).getNodeName().equals("Gender"))
                ...{
                    gender=schema.get_any()[1].getChildNodes().item(0).getChildNodes().item(i).getChildNodes().item(1).getFirstChild().getNodeValue();
                }   
                model.addRow(new String[]...{name,gender});
                this.jScrollPane1.getViewport().add(jTable1, null);
            }
            jTable1.setModel(model);       
      }
      catch (Exception ex)
      ...{            
          System.err.println(ex.toString());
      }             



4. 小结
  
  从前面的叙述和代码中可以看出,对于"如何在Java/Delphi中使用.NET的Web Service返回的DataSet"的问题,虽然在非.NET语言环境中直接接受DataSet类型的返回值比较困难,但可以有其他的解决方案。
分享到:
评论

相关推荐

    axis2.jar 解决 org.apache.axis2.util.JavaUtils.callStackToString问题

    &lt;Call Stack = DEBUG_FRAME = org.apache.axis2.util.JavaUtils.callStackToString(JavaUtils.java:564) DEBUG_FRAME = org.apache.axis2.description.ParameterIncludeImpl.debugParameterAdd(ParameterIncludeImpl...

    抛出无法找到主类:org.apache.axis.wsdl.WSDL2Java

    抛出无法找到主类:org.apache.axis.wsdl.WSDL2Java(Throws Could not find main class: org.apache.axis.wsdl.WSDL2Java)。 添加本文的jar包压缩包解压出来的所有jar包到当前使用的java.exe 命令的lib目录下的ext...

    axis2解决 org.apache.axis2.util.JavaUtils.callStackToString问题

    在开发基于Axis2的Web服务时,可能会遇到各种错误和异常,其中之一就是与`org.apache.axis2.util.JavaUtils.callStackToString`相关的问题。这个问题通常出现在Axis2尝试获取并打印堆栈跟踪信息时。 `...

    org.apache.axis2.jar

    org.apache.axis2.jar

    org.apache.axis jar

    4. **服务部署**:`org.apache.axis.jar`中的类用于处理服务的部署,包括解析WSDL文件,生成服务处理逻辑,以及将服务发布到应用服务器上。 5. **客户端调用**:对于Web服务的消费者,Axis提供了解析WSDL并生成...

    org.apache.axis2.eclipse.service.plugin_1.7.8

    `org.apache.axis2.eclipse.service.plugin_1.7.8`是专门为Eclipse设计的一个插件,旨在简化在Eclipse中使用和管理Apache Axis2服务的过程。 这个插件的主要功能包括: 1. **Axis2服务创建**:它允许用户直接在...

    eclipse插件 org.apache.axis2.eclipse.codegen.plugin_1.7.4.jar

    eclipse插件 org.apache.axis2.eclipse.codegen.plugin_1.7.4.jar

    axis 1.x与axis2.x开发

    Axis是Apache组织开发的一款开源Web服务框架,主要用于构建和部署SOAP(Simple Object Access Protocol)服务。Axis分为两个主要版本:Axis1.x和Axis2.x,它们都是Java平台上的Web服务实现,但在设计和功能上有所...

    eclipse 插件org.apache.axis2.eclipse.service.plugin_1.7.8

    eclipse 4.9.0 插件org.apache.axis2.eclipse.service.plugin_1.7.8

    org.apache.axis2.eclipse.codegen.plugin_1.6.3

    "org.apache.axis2.eclipse.codegen.plugin_1.6.3"和"org.apache.axis2.eclipse.service.plugin_1.6.3"这两个插件就是针对这个目的设计的,它们都属于Apache Axis2的Eclipse扩展。 `org.apache.axis2.eclipse....

    基于java的开发源码-Web服务框架 Apache Axis.zip

    基于java的开发源码-Web服务框架 Apache Axis.zip 基于java的开发源码-Web服务框架 Apache Axis.zip 基于java的开发源码-Web服务框架 Apache Axis.zip 基于java的开发源码-Web服务框架 Apache Axis.zip 基于java的...

    eclipse插件 org.apache.axis2.eclipse.service.plugin_1.7.4.jar

    eclipse插件 org.apache.axis2.eclipse.service.plugin_1.7.4.jar

    org.apache.axis2.eclipse.codegen.plugin_1.7.8.jar

    "org.apache.axis2.eclipse.codegen.plugin_1.7.8.jar"是这个插件的特定版本,版本号为1.7.8。 该插件的主要功能包括: 1. **服务客户端生成**:基于WSDL(Web Services Description Language)文件,可以自动生成...

    axis 代码jar包

    Axis是Apache软件基金会开发的一个开放源代码的SOAP(简单对象访问协议)服务器和客户端实现,主要用于Web服务。本文将深入探讨Axis的相关知识点,特别是关于"axis-1.4 jar包"的内容。 一、Axis简介 Axis是Java...

    axis2.eclipse.service.plugin-1.5.1-sources.jar

    标签:axis2.eclipse.service.plugin-1.5.1-sources.jar,axis2.eclipse.service.plugin,1.5.1,sources,jar包下载,依赖包

    Tomcat_与_Apache_AXIS集成.pdf

    下载地址为:[http://archive.apache.org/dist/xml/xerces-j/](http://archive.apache.org/dist/xml/xerces-j/),需要下载`Xerces-J-bin.2.11.0.zip`。 6. **Xmlsec.jar**:这是一个用于加密和签名XML文档的安全库。...

    TipTec.Developing.Web.Services.with.Apache.CXF.and.Axis2.Jan.2010.rar

    标题中的“TipTec.Developing.Web.Services.with.Apache.CXF.and.Axis2.Jan.2010”表明这是一份关于使用Apache CXF和Axis2开发Web服务的教程资料,发布于2010年1月。Apache CXF和Axis2是两个流行的Java框架,用于...

    jquery.flot.axislabels.js

    jquery.flot.axislabels.js

    axis1.4.1.zip

    标题“axis1.4.1.zip”所指的是一份针对Axis1.4版本的修复补丁包,这个补丁主要是为了解决在Java Development Kit (JDK) 1.8环境下,高并发场景下出现的`ConcurrentModificationException`问题。`...

Global site tag (gtag.js) - Google Analytics