webServices学习之二——axis1传递复杂类型javabean

            继续axis1的实现,传递复杂类型javabean:

 

一、服务端:

 服务端需要在server-config.wsdd文件中要发布的service 中加入 beanMapping  指定要 传递JavaBean的类型,

见红色部分:

 

 

 <service name="MyServices" provider="java:RPC">
  <parameter name="allowedMethods" value="*"/>
  <parameter name="className" value="haohao.MyServices"/>
  <beanMapping languageSpecificType="java:haohao.User"    
    	qname="ns:User" xmlns:ns="urn:User"/>
 </service>
 

 

发布成功后的wsdl文件,有对JavaBean类型的描述:

 

 

<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:User">
	<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
	<complexType name="User">
		<sequence>
			<element name="id" nillable="true" type="xsd:long"/>
			<element name="pwd" nillable="true" type="xsd:string"/>
			<element name="username" nillable="true" type="xsd:string"/>
		</sequence>
	</complexType>
</schema>
</wsdl:types>

 

 

二、客户端调用:

 

 

private static String nameSpaceUri = "http://localhost:8080/axisTest/services/MyServices";
Service service = new Service();
			Call call = (Call) service.createCall();
			QName qn = new QName("urn:BeanService","SimpleObject");
			call.registerTypeMapping(User.class, qn,
			 new BeanSerializerFactory(User.class, qn),
			 new BeanDeserializerFactory(User.class, qn));
			
			call.setTargetEndpointAddress(new java.net.URL(serviceUrl));

			call.setOperationName(new QName(nameSpaceUri, "sayHello"));
			str = (String) call.invoke(new Object [] {createMorkUser()});
 

 

 

你可能感兴趣的:(webServices学习之二——axis1传递复杂类型javabean)