1. Use jaxws
The configuration method is as follows:
<bean id="tradeService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean"> <property name="serviceInterface" value="com.webservice.test.trade.TradeService" /> <property name="namespaceUri" value="http://trade.test.webservice.com/" /> <property name="wsdlDocumentUrl" value="http://127.0.0.1:8080/webservice/tradeService?wsdl" /> <property name="serviceName" value="tradeService" /> <property name="portName" value="tradeServiceImplPort" /> </bean>
If you only know the access path (wsdlDocumentUrl) and you are not sure about other parameters, you can first ensure that the access path is correct, and the other parameters (namespaceUri, serviceName, portName) can be modified one by one according to the error prompts.
TradeService code:
package com.webservice.test.trade; import javax.jws.WebService; @WebService public interface TradeService { String callServiceXml(@WebParam(name="xml")String xml); }
Notice:
a. For the package path of the interface class and related classes, it must be the same as that of the server, otherwise it will appear
Unexpected wrapper element {****}tradeService found.……错误。
In fact, the namespaceUri parameter is the path of the server package
The path on the corresponding server of http://trade.test.webservice.com/ is com.webservice.test.trade
b. The interface parameters must be marked with @WebParam(name="xml"), otherwise it will appear:
JaxWsSoapFaultException: Unmarshalling Error: unexpected element (uri:"", local:"arg0")错误。
c. If it is all communication between Java projects, in order to avoid some unnecessary situations, you can let the server package the interface and send it to the client caller to ensure that the path is consistent.
2. WebServiceTemplate using spring ws
The configuration method is as follows:
<bean id="xxxWebService" class="org.springframework.ws.client.core.WebServiceTemplate"> <property name="defaultUri" value="http://XXX.net:8080"/> </bean>
3. Use CXF
The configuration method is as follows:
<import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <jaxws:client id="xxxWebService" serviceClass="com.xxx.UploadFileService" address="http://XXX.net:8080"> </jaxws:client>
Fourth, use the xfire
configuration method as follows:
<bean id ="dwdsspWebService" class ="org.codehaus.xfire.spring.remoting.XFireClientFactoryBean"> <property name ="serviceClass"> <value>com.xxx.UploadFileService</value> </property> <property name ="wsdlDocumentUrl"> <value>http://XXX.net:8080/XXXServicePort?WSDL</value> </property> </bean>
In the current project, it is mainly the communication between java projects. I have been using Spring RMI and Spring to integrate hessian before, and I am more used to the way of public jar packages, so I only tried the first way of calling the server from the client.
The reference address is as follows:
http://blog.csdn.net/kkdelta/article/details/7290769
http://blog.csdn.net/fu9958/article/details/5959262
http://blog.csdn.net/kkdelta/article/details/3987591
http://blog.csdn.net/jadyer/article/details/9002984
http://blog.csdn.net/vickychen89/article/details/6606571
http://coach.iteye.com/blog/894159
http://my.oschina.net/zimingforever/blog/212492