简体   繁体   中英

Consuming an external web service using Spring 3.1

I'm trying to access an external webservice from Spring 3.1 based application. I want to call this web service method called "ListProductNames" with one string argument and read the response. The necessary portion from the WSDL and Schema files are as below:

...
...
<operation name="ListProductNames">
<soap:operation soapAction="urn:ListProductNames" style="document"/>
<input><soap:body use="literal"/></input>
<output><soap:body use="literal"/></output>
</operation>

<message name="ListProductNamesIn">
<part name="parameter" element="tns:ListProductNamesRequest"/>
</message>
<message name="ListProductNamesOut">
<part name="parameter" element="tns:ListProductNames"/>
</message>

...

<s:element name="ListProductNamesRequest">
<s:complexType>
<s:sequence>
<s:element name="NameFilter" type="s:string" minOccurs="0"/>
</s:sequence>
</s:complexType>
</s:element>

<s:element name="ListProductNames">
<s:complexType>
<s:sequence>
<s:element name="Product" type="tns:ProductNameType" minOccurs="0" maxOccurs="unbounded"/>
</s:sequence>
</s:complexType>
</s:element>

<s:complexType name="ProductNameType">
<s:sequence>
<s:element name="Name" type="s:string"/>
<s:element name="Identifier" type="s:int"/>
<s:element name="Marketer" type="s:string"/>
</s:sequence>
</s:complexType>

I've configured the bean as below:

<bean id="myWebService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
    <property name="serviceInterface" value="com.xyz.TestService"/>
    <property name="wsdlDocumentUrl" value="http://servername.net:6464/WSTest.wsdl"/>
    <property name="namespaceUri" value="http://test.abcd.com/"/>
    <property name="serviceName" value="TestService"/>
    <property name="portName" value="TestServiceSoap"/>
</bean> 

Now I'm trying to create the Service Interface. This is where I'm having trouble.

@WebService(name="TestServiceSoap", targetNamespace="http://test.abcd.com/")
public interface MyWebService {
@WebMethod(operationName="ListProductNames", action="urn:ListProductNames")
@WebResult(name="Product", targetNamespace="http://test.abcd.com/")
@RequestWrapper(localName="ListProductNamesRequest", targetNamespace="http://test.abcd.com/", className="??")
@ResponseWrapper(localName="ListProductNames", targetNamespace="http://test.abcd.com/", className="??")
public String listProductNames(@WebParam(name="NameFilter", targetNamespace="http://test.abcd.com/") String name);
}

Since both the request and responses are complex types (as specified in the WSDL), I'm not sure how to specify them in the annotation above. Also, what do I specify as the "className" in the request and response wrappers. Do I have to create additional classes for this call to work?

It's usually considered better practice to use top-down approach when developing web services. Start with XML schema, then run 'wsimport' (part of JDK) to generate your classes and interfaces. It should generate you stub file for service and client as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM