`
douh
  • 浏览: 16583 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

AXIS2 RCP/literal样式,两种MESSAGE定义方式SOAP的payload

阅读更多
没有COMPLEXTYPE的MESSAGE WSDL文件内容
清单1:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://www.ctgx.com/RPCService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="RPCService"
	targetNamespace="http://www.ctgx.com/RPCService/">
	<wsdl:message name="concatRequest">
		<wsdl:part name="s1" type="xsd:string" />
		<wsdl:part name="s2" type="xsd:string"/>
	</wsdl:message>
	<wsdl:message name="concatResponse">
		<wsdl:part name="out" type="xsd:string" />
	</wsdl:message>
	<wsdl:portType name="RPCService">
		<wsdl:operation name="concat">
			<wsdl:input message="tns:concatRequest" />
			<wsdl:output message="tns:concatResponse" />
		</wsdl:operation>
	</wsdl:portType>
	<wsdl:binding name="RPCServiceSOAP" type="tns:RPCService">
		<soap:binding style="rpc"
			transport="http://schemas.xmlsoap.org/soap/http" />
		<wsdl:operation name="concat">
			<soap:operation soapAction="http://www.ctgx.com/RPCService/concat" />
			<wsdl:input>
				<soap:body namespace="http://www.ctgx.com/RPCService/"
					use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body namespace="http://www.ctgx.com/RPCService/"
					use="literal" />
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>
	<wsdl:service name="RPCService">
		<wsdl:port binding="tns:RPCServiceSOAP" name="RPCServiceSOAP">
			<soap:address location="http://localhost:8080/axis2/services/RPCService" />
		</wsdl:port>
	</wsdl:service>
</wsdl:definitions>
清单2:

客户端调用时,直接使用AXIOM(lowlevel)的代码:
package com.ctgx.www.rpcservice;

import javax.xml.namespace.QName;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

/**
 * filename:LowLevelClient.java description: the file desciption goes here
 * Copyright: Copyright(c)2010 CTGX *
 * 
 * @author: 梁明杰
 * @version: 1.0 Create at: 2010-7-28 下午04:47:45
 * 
 */
public class LowLevelClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws AxisFault {
		ServiceClient client = new ServiceClient();
		Options options = new Options();
		//采用这种方式必须设定HTTP SOAPAction Header
		options.setAction("http://www.ctgx.com/RPCService/concat");
		options.setTo(new EndpointReference(
				"http://localhost:1234/axis2/services/RPCService?wsdl"));
		client.setOptions(options);
		OMElement request = makeRequest();
		OMElement response = client.sendReceive(request);
		System.out.println(response.toString());

	}

	private static OMElement makeRequest() {
		OMFactory factory = OMAbstractFactory.getOMFactory();
		OMElement request = factory.createOMElement(new QName(
				"http://www.ctgx.com/RPCService/", "concat"));
		OMElement s1 = factory.createOMElement(new QName("s1"));
		s1.setText("abc");
		OMElement s2 = factory.createOMElement(new QName("s2"));
		s2.setText("123");
		request.addChild(s2);
		request.addChild(s1);
		return request;

	}

}


对应的SOAP消息如下:
清单3:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <soapenv:Body>
         <axis2ns1:concat xmlns:axis2ns1="http://www.ctgx.com/RPCService/">
            <s2>123</s2>
            <s1>abc</s1>
         </axis2ns1:concat>
      </soapenv:Body>
   </soapenv:Envelope>


使用COMPLEXTYPE的MESSAGE WSDL文件内容
清单4:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://www.ctgx.com/SimpleService1/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SimpleService1"
	targetNamespace="http://www.ctgx.com/SimpleService1/">
	<wsdl:types>
		<xsd:schema targetNamespace="http://www.ctgx.com/SimpleService1/">
			<xsd:complexType name="concat">
				<xsd:sequence>
					<xsd:element name="s1" type="xsd:string" />
					<xsd:element name="s2" type="xsd:string"></xsd:element>
				</xsd:sequence>
			</xsd:complexType>
			<xsd:complexType name="concatResponse">
				<xsd:sequence>
					<xsd:element name="out" type="xsd:string" />
				</xsd:sequence>
			</xsd:complexType>
		</xsd:schema>
	</wsdl:types>
	<wsdl:message name="concatRequest">
		<wsdl:part type="tns:concat" name="parameters" />
	</wsdl:message>
	<wsdl:message name="concatResponse">
		<wsdl:part type="tns:concatResponse" name="parameters" />
	</wsdl:message>
	<wsdl:portType name="SimpleService1">
		<wsdl:operation name="concat">
			<wsdl:input message="tns:concatRequest" />
			<wsdl:output message="tns:concatResponse" />
		</wsdl:operation>
	</wsdl:portType>
	<wsdl:binding name="SimpleServiceSOAP" type="tns:SimpleService1">
		<soap:binding style="rpc"
			transport="http://schemas.xmlsoap.org/soap/http" />
		<wsdl:operation name="concat">
			<soap:operation soapAction="http://www.ctgx.com/SimpleService1/concat" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>
	<wsdl:service name="SimpleService">
		<wsdl:port binding="tns:SimpleServiceSOAP" name="SimpleServiceSOAP">
			<soap:address location="http://localhost:8080/axis2/services/SimpleService1" />
		</wsdl:port>
	</wsdl:service>
</wsdl:definitions>


客户端测试代码:
清单5:
package com.ctgx.www.simpleservice1;

import javax.xml.namespace.QName;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

/**
 * filename:LowLevelClient.java description: the file desciption goes here
 * Copyright: Copyright(c)2010 CTGX *
 * 
 * @author: 梁明杰
 * @version: 1.0 Create at: 2010-7-28 下午04:47:45
 * 
 */
public class LowLevelClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws AxisFault {
		ServiceClient client = new ServiceClient();
		Options options = new Options();
		options.setAction("http://www.ctgx.com/SimpleService1/concat");
		options.setTo(new EndpointReference(
				"http://localhost:1234/axis2/services/SimpleService1"));
		client.setOptions(options);
		OMElement request = makeRequest();
		OMElement response = client.sendReceive(request);
		System.out.println(response.toString());

	}

	private static OMElement makeRequest() {
		OMFactory factory = OMAbstractFactory.getOMFactory();
		OMElement request = factory.createOMElement(new QName(
				"http://www.ctgx.com/SimpleService1/", "concat"));
		OMElement parameters=factory.createOMElement(new QName("parameters"));
		OMElement s1 = factory.createOMElement(new QName("s1"));
		s1.setText("abc");
		OMElement s2 = factory.createOMElement(new QName("s2"));
		s2.setText("123");
		request.addChild(parameters);
		parameters.addChild(s1);
		parameters.addChild(s2);
		return request;

	}

}


SOAP消息
清单6:
 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <soapenv:Body>
         <axis2ns1:concat xmlns:axis2ns1="http://www.ctgx.com/SimpleService1/">
            <parameters>
               <s1>abc</s1>
               <s2>123</s2>
            </parameters>
         </axis2ns1:concat>
      </soapenv:Body>
   </soapenv:Envelope>

需要说明的地方:
第一,清单1没有使用COMPLEXTYPE,清单4使用了COMPLEXTYPE 所以导致清单3和清单6的SOAP BODY 的消息不同。清单3中两个参数S1和S2直接包含在方法名concat中,且名字和MESSAGE的PART的名字相同。清单6中两个参数S1和S2包含在parameters中,parameters比如和MESSAGE part的名字,且PARAMETERS的两个元素就是COMPLEXTYPE中定义的元素。在SOAP中不能有类型和元素的引用,PARAMETERS实际上就构成了一个复合元素。
第二,清单3和清单6中S1和S2的顺序不同,这和AXIS2生成的服务端代码有关系。也就是说,MESSAGE中的PART顺序,不一定是方法中参数的顺序,不过使用COMPLEXTYPE方式定义,可以保证这一点。这和AXIS2的数据绑定有关系。
第三点,AXIS2对RCP/LITERAL的支持,实际上是DOCOMENT WRAPPER方式,也就是说,在RCP/LITERAL代码生成过程中,AXIS2做包装转换
附件是TCPMON应用程序,用来捕捉SOAP信息非常方便
分享到:
评论

相关推荐

    axis1.4 + document/literal 实例

    学习axis容器document/literal样式的好例子,值得一看。

    axis2 调用webservice 例子

    &lt;groupId&gt;org.apache.axis2&lt;/groupId&gt; &lt;artifactId&gt;axis2&lt;/artifactId&gt; &lt;version&gt;1.6.2&lt;/version&gt; &lt;/dependency&gt; &lt;groupId&gt;org.apache.axis2&lt;/groupId&gt; &lt;artifactId&gt;axis2-adb&lt;/...

    eclipse java axis2

    eclipse java axis2 http://axis.apache.org/axis2/java/core/download.cgi

    axis2c-src-1.6.0

    Axis2/C supports both SOAP 1.1 and SOAP 1.2. The soap processing model is built on the AXIOM XML object model. Axis2/C is capable of handling one-way messaging (In-Only) as well as request ...

    axis2 for c++ 1.6

    The Apache Axis2/C is a SOAP engine implementation that can be used to provide and consume Web Services. Axis2/C is an effort to implement Axis2 architecture, in C. Please have a look at ...

    axis2 soap技术

    axis2 soap技术 wsdl技术 java 的技术

    Axis2 Webservice端例子

    Axis2 Webservice端例子Axis2 Webservice端例子

    axis2发布webServices的两种方式

    其中包括两种利用axis2发布WebService的程序。一种是将项目直接集成到axis2内部里面,一种是将axis2集成到已有的项目中。各有优缺点。

    axis2的eclispe 插件

    axis2的eclispe插件分为2个,一个是帮助我们生成aar文件的,另一个是帮我们用wsdl文件生成stub代码的 官网下载地址是: ...

    axis2/c linux 安装步骤

    axis2/c linux 安装步骤

    axis2 1.7.4war及已经集成了axis2的web工程

    包含了 axis2 1.7.4版本的war包 也可以自行去 apache官网下载 ,另外还包含一个已经集成了axis2的web工程源码 使用的jdk1.6开发,可以直接把web工程导入到myeclipse,部署到tomcat可运行后,浏览器输入 ...

    axis2-1.6.2.zip

    axis2-1.6.2.zip, windows axis2工具,根据 WSDL生成java文件。 1、axis2客户端下载地址:http://mirror.esocc.com/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip; 2、下载解压在D:\Work_Program_...

    axis2-1.6.2

    axis2-1.6.2.zip, windows axis2工具,根据 WSDL生成java文件。 1、axis2客户端下载地址:http://mirror.esocc.com/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip; 2、下载解压在D:\Work_Program_...

    SOAP生成使用的AXIS2

    AXIS2结合IDEA快速生成JAVA类,如果需要将SOAP报文装成JAVA对象,下载,IDEA中配置

    SOAP Axis 三种发布调用方式简单实例

    比较简单的SOAP Axis三种发布、调用方式简单的实例,代码和文档都在,不包含AXIS包,需要自行下载。

    Building a JSON web service with Java and Axis2

    1.Download Axis2 as WAR and install it in your servlet container 2.Download the DynamicResponseHandler module and add it to Axis by copying it to WEB-INF/modules 3.Patch Jettison or download my ...

    myeclipse8.5使用axis2插件开发webservice服务并调用--操作步骤图解

    使用myeclipse8.5安装axis2插件,工程主要是通过server端类生成服务,生成客户端。 1、使用服务端类com.Hello.java,com.Other.java生成wsdl、aar文件【aar文件通过axis2插件的Axis2 service archiver生成】【wsdl...

    eclipse的Axis2插件

    axis2-eclipse-codegen-wizard.zip和axis2-eclipse-service-archiver-wizard.zip 解压后得到两个文件夹:Axis2_Codegen_Wizard_1.3.0和Axis2_Service_Archiver_1.3.0,拷贝至eclipse\dropins,重启eclipse即可。

    axis2方式开发webservice

    myeclipse安装axis2.txt文件:详细说明了myeclipse如何安装axis2插件,以及编写简单的服务端代码,以及axis2客户端访问服务端的几种方式。 axisdemo是一个普通的javaweb工程,里面有一个简单的接口,在此工程的基础...

Global site tag (gtag.js) - Google Analytics