Java SpringSOAPWS客户端
例如,我正在努力调用puroposes,一个用SpringWS公开的soap ws: 这里是部署在tomcat上的wsdlJava SpringSOAPWS客户端,java,spring,web-services,soap,spring-ws,Java,Spring,Web Services,Soap,Spring Ws,例如,我正在努力调用puroposes,一个用SpringWS公开的soap ws: 这里是部署在tomcat上的wsdl <!--Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.3-b01-.--> <!--Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS
<!--Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.3-b01-.-->
<!--Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.3-b01-.-->
<definitions targetNamespace="http://ws.mkyong.com/" name="HelloWorldWSService" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.mkyong.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema>
<xsd:import namespace="http://ws.mkyong.com/" schemaLocation="http://localhost:8080/web_services/hello?xsd=1"/>
</xsd:schema>
</types>
<message name="findById">
<part name="parameters" element="tns:findById"/>
</message>
<message name="findByIdResponse">
<part name="parameters" element="tns:findByIdResponse"/>
</message>
<message name="saveJob">
<part name="parameters" element="tns:saveJob"/>
</message>
<message name="saveJobResponse">
<part name="parameters" element="tns:saveJobResponse"/>
</message>
<message name="findJobByName">
<part name="parameters" element="tns:findJobByName"/>
</message>
<message name="findJobByNameResponse">
<part name="parameters" element="tns:findJobByNameResponse"/>
</message>
<message name="findJobByRole">
<part name="parameters" element="tns:findJobByRole"/>
</message>
<message name="findJobByRoleResponse">
<part name="parameters" element="tns:findJobByRoleResponse"/>
</message>
<message name="deleteJob">
<part name="parameters" element="tns:deleteJob"/>
</message>
<message name="deleteJobResponse">
<part name="parameters" element="tns:deleteJobResponse"/>
</message>
<message name="getAllJobs">
<part name="parameters" element="tns:getAllJobs"/>
</message>
<message name="getAllJobsResponse">
<part name="parameters" element="tns:getAllJobsResponse"/>
</message>
<message name="updateJob">
<part name="parameters" element="tns:updateJob"/>
</message>
<message name="updateJobResponse">
<part name="parameters" element="tns:updateJobResponse"/>
</message>
<portType name="HelloWorldWS">
<operation name="findById">
<input wsam:Action="http://ws.mkyong.com/HelloWorldWS/findByIdRequest" message="tns:findById"/>
<output wsam:Action="http://ws.mkyong.com/HelloWorldWS/findByIdResponse" message="tns:findByIdResponse"/>
</operation>
<operation name="saveJob">
<input wsam:Action="http://ws.mkyong.com/HelloWorldWS/saveJobRequest" message="tns:saveJob"/>
<output wsam:Action="http://ws.mkyong.com/HelloWorldWS/saveJobResponse" message="tns:saveJobResponse"/>
</operation>
<operation name="findJobByName">
<input wsam:Action="http://ws.mkyong.com/HelloWorldWS/findJobByNameRequest" message="tns:findJobByName"/>
<output wsam:Action="http://ws.mkyong.com/HelloWorldWS/findJobByNameResponse" message="tns:findJobByNameResponse"/>
</operation>
<operation name="findJobByRole">
<input wsam:Action="http://ws.mkyong.com/HelloWorldWS/findJobByRoleRequest" message="tns:findJobByRole"/>
<output wsam:Action="http://ws.mkyong.com/HelloWorldWS/findJobByRoleResponse" message="tns:findJobByRoleResponse"/>
</operation>
<operation name="deleteJob">
<input wsam:Action="http://ws.mkyong.com/HelloWorldWS/deleteJobRequest" message="tns:deleteJob"/>
<output wsam:Action="http://ws.mkyong.com/HelloWorldWS/deleteJobResponse" message="tns:deleteJobResponse"/>
</operation>
<operation name="getAllJobs">
<input wsam:Action="http://ws.mkyong.com/HelloWorldWS/getAllJobsRequest" message="tns:getAllJobs"/>
<output wsam:Action="http://ws.mkyong.com/HelloWorldWS/getAllJobsResponse" message="tns:getAllJobsResponse"/>
</operation>
<operation name="updateJob">
<input wsam:Action="http://ws.mkyong.com/HelloWorldWS/updateJobRequest" message="tns:updateJob"/>
<output wsam:Action="http://ws.mkyong.com/HelloWorldWS/updateJobResponse" message="tns:updateJobResponse"/>
</operation>
</portType>
<binding name="HelloWorldWSPortBinding" type="tns:HelloWorldWS">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="findById">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="saveJob">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="findJobByName">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="findJobByRole">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="deleteJob">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="getAllJobs">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="updateJob">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="HelloWorldWSService">
<port name="HelloWorldWSPort" binding="tns:HelloWorldWSPortBinding">
<soap:address location="http://localhost:8080/web_services/hello"/>
</port>
</service>
</definitions>
我想定义一个简单的客户机来测试它,用一个main方法就好了,用SpringWS调用它们,如果你给我一些建议或链接就好了,也许可以举一个例子,说明在WS方法没有参数的情况下,如何调用它们发送一个对象作为请求参数并发送一个空的输入请求
任何对链接或代码片段的引用都会有很大的帮助,我发现了这么多不同的示例,没有一个适合我的需要,我现在有点困惑。我建议使用Spring WebService Template WebServiceTemplate- WebServiceTemplate是SpringWS中客户端Web服务访问的核心类。它包含用于发送源对象和接收作为源或结果的响应消息的方法。此外,它可以在通过传输发送对象之前将对象封送到XML,并再次将任何响应XML解组到对象中 步骤1: 使用WSDL生成对象的示例:
1. Copy you are WSDL file into local directory
2. Open Command Promote
3. wsimport -p mypackage -keep -verbose myservice.wsdl
This command generated object request and response
步骤2:
Soap消息工厂的ApplicationContext.xml配置
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="soapVersion">
<util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12" />
</property>
</bean>
有关更多信息,请参阅下面的链接
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPaths" value="package"/>
</bean>
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory" />
<property name="marshaller" ref="marshaller"></property>
<property name="unmarshaller" ref="marshaller"></property>
<property name="defaultUri" value="wsdlLocation" />
</bean>
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.client.core.WebServiceTemplate;
class ClientConnection {
@Autowired
private WebServiceTemplate webServiceTemplate;
public synchronized Object sendRequestAndReceive(Object xmlRequest,
final String uri) {
webServiceTemplate.setDefaultUri(uri);
Object object = webServiceTemplate.marshalSendAndReceive(xmlRequest);
return object;
}
}