Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web service client given WSDL

I am trying to create a web service client in Java. I am not aware of how to do it. This is a URL for WSDL: https://testservices.gatewayedi.com/PayerList/payerlist.asmx?wsdl

This is the WSDL:

<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="https://ws.gatewayedi.com/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="https://ws.gatewayedi.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">   <wsdl:types>     <s:schema elementFormDefault="qualified" targetNamespace="https://ws.gatewayedi.com/">       <s:element name="Ping">         <s:complexType />       </s:element>       <s:element name="PingResponse">         <s:complexType>           <s:sequence>             <s:element minOccurs="0" maxOccurs="1" name="PingResult" type="s:string" />           </s:sequence>         </s:complexType>       </s:element>       <s:element name="AuthSOAPHeader" type="tns:AuthSOAPHeader" />       <s:complexType name="AuthSOAPHeader">         <s:sequence>           <s:element minOccurs="0" maxOccurs="1" name="User" type="s:string" />           <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />         </s:sequence>         <s:anyAttribute />       </s:complexType>       <s:element name="GetXMLPayerList">         <s:complexType />       </s:element>       <s:element name="GetXMLPayerListResponse">         <s:complexType>           <s:sequence>             <s:element minOccurs="0" maxOccurs="1" name="GetXMLPayerListResult" type="s:string" />           </s:sequence>         </s:complexType>       </s:element>       <s:element name="getDocLinks">         <s:complexType>           <s:sequence>             <s:element minOccurs="0" maxOccurs="1" name="pid" type="s:string" />           </s:sequence>         </s:complexType>       </s:element>       <s:element name="getDocLinksResponse">         <s:complexType>           <s:sequence>             <s:element minOccurs="0" maxOccurs="1" name="getDocLinksResult" type="s:string" />           </s:sequence>         </s:complexType>       </s:element>     </s:schema>   </wsdl:types>   <wsdl:message name="PingSoapIn">     <wsdl:part name="parameters" element="tns:Ping" />   </wsdl:message>   <wsdl:message name="PingSoapOut">     <wsdl:part name="parameters" element="tns:PingResponse" />   </wsdl:message>   <wsdl:message name="PingAuthSOAPHeader">     <wsdl:part name="AuthSOAPHeader" element="tns:AuthSOAPHeader" />   </wsdl:message>   <wsdl:message name="GetXMLPayerListSoapIn">     <wsdl:part name="parameters" element="tns:GetXMLPayerList" />   </wsdl:message>   <wsdl:message name="GetXMLPayerListSoapOut">     <wsdl:part name="parameters" element="tns:GetXMLPayerListResponse" />   </wsdl:message>   <wsdl:message name="GetXMLPayerListAuthSOAPHeader">     <wsdl:part name="AuthSOAPHeader" element="tns:AuthSOAPHeader" />   </wsdl:message>   <wsdl:message name="getDocLinksSoapIn">     <wsdl:part name="parameters" element="tns:getDocLinks" />   </wsdl:message>   <wsdl:message name="getDocLinksSoapOut">     <wsdl:part name="parameters" element="tns:getDocLinksResponse" />   </wsdl:message>   <wsdl:message name="getDocLinksAuthSOAPHeader">     <wsdl:part name="AuthSOAPHeader" element="tns:AuthSOAPHeader" />   </wsdl:message>   <wsdl:portType name="PayerListSoap">     <wsdl:operation name="Ping">       <wsdl:input message="tns:PingSoapIn" />       <wsdl:output message="tns:PingSoapOut" />     </wsdl:operation>     <wsdl:operation name="GetXMLPayerList">       <wsdl:input message="tns:GetXMLPayerListSoapIn" />       <wsdl:output message="tns:GetXMLPayerListSoapOut" />     </wsdl:operation>     <wsdl:operation name="getDocLinks">       <wsdl:input message="tns:getDocLinksSoapIn" />       <wsdl:output message="tns:getDocLinksSoapOut" />     </wsdl:operation>   </wsdl:portType>   <wsdl:binding name="PayerListSoap" type="tns:PayerListSoap">     <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />     <wsdl:operation name="Ping">       <soap:operation soapAction="https://ws.gatewayedi.com/Ping" style="document" />       <wsdl:input>         <soap:body use="literal" />         <soap:header message="tns:PingAuthSOAPHeader" part="AuthSOAPHeader" use="literal" />       </wsdl:input>       <wsdl:output>         <soap:body use="literal" />       </wsdl:output>     </wsdl:operation>     <wsdl:operation name="GetXMLPayerList">       <soap:operation soapAction="https://ws.gatewayedi.com/GetXMLPayerList" style="document" />       <wsdl:input>         <soap:body use="literal" />         <soap:header message="tns:GetXMLPayerListAuthSOAPHeader" part="AuthSOAPHeader" use="literal" />       </wsdl:input>       <wsdl:output>         <soap:body use="literal" />       </wsdl:output>     </wsdl:operation>     <wsdl:operation name="getDocLinks">       <soap:operation soapAction="https://ws.gatewayedi.com/getDocLinks" style="document" />       <wsdl:input>         <soap:body use="literal" />         <soap:header message="tns:getDocLinksAuthSOAPHeader" part="AuthSOAPHeader" use="literal" />       </wsdl:input>       <wsdl:output>         <soap:body use="literal" />       </wsdl:output>     </wsdl:operation>   </wsdl:binding>   <wsdl:binding name="PayerListSoap12" type="tns:PayerListSoap">     <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />     <wsdl:operation name="Ping">       <soap12:operation soapAction="https://ws.gatewayedi.com/Ping" style="document" />       <wsdl:input>         <soap12:body use="literal" />         <soap12:header message="tns:PingAuthSOAPHeader" part="AuthSOAPHeader" use="literal" />       </wsdl:input>       <wsdl:output>         <soap12:body use="literal" />       </wsdl:output>     </wsdl:operation>     <wsdl:operation name="GetXMLPayerList">       <soap12:operation soapAction="https://ws.gatewayedi.com/GetXMLPayerList" style="document" />       <wsdl:input>         <soap12:body use="literal" />         <soap12:header message="tns:GetXMLPayerListAuthSOAPHeader" part="AuthSOAPHeader" use="literal" />       </wsdl:input>       <wsdl:output>         <soap12:body use="literal" />       </wsdl:output>     </wsdl:operation>     <wsdl:operation name="getDocLinks">       <soap12:operation soapAction="https://ws.gatewayedi.com/getDocLinks" style="document" />       <wsdl:input>         <soap12:body use="literal" />         <soap12:header message="tns:getDocLinksAuthSOAPHeader" part="AuthSOAPHeader" use="literal" />       </wsdl:input>       <wsdl:output>         <soap12:body use="literal" />       </wsdl:output>     </wsdl:operation>   </wsdl:binding>   <wsdl:service name="PayerList">     <wsdl:port name="PayerListSoap" binding="tns:PayerListSoap">       <soap:address location="https://testservices.gatewayedi.com/PayerList/payerlist.asmx" />     </wsdl:port>     <wsdl:port name="PayerListSoap12" binding="tns:PayerListSoap12">       <soap12:address location="https://testservices.gatewayedi.com/PayerList/payerlist.asmx" />     </wsdl:port>   </wsdl:service> </wsdl:definitions> 

There are three methods in the service.

I am trying to call this method using SOAP.

The XML message format is:

POST /PayerList/payerlist.asmx HTTP/1.1  Host: testservices.gatewayedi.com  Content-Type: application/soap+xml; charset=utf-8  Content-Length: <<insert message length here>>  <?xml version="1.0" encoding="utf-8"?>  <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Header> <AuthSOAPHeader xmlns="https://ws.gatewayedi.com/"> <User><<insert user id here>> </User>  <Password><<insert user web password here>> </Password>  </AuthSOAPHeader>  </soap12:Header> <soap12:Body> <Ping xmlns="https://ws.gatewayedi.com/" />  </soap12:Body>  </soap12:Envelope>  

Anyone who knows the solution please let me know. Any help is really appreciable.

like image 352
user506518 Avatar asked Nov 13 '10 10:11

user506518


People also ask

How do I create a web service client from WSDL?

Generate the client code as follows: In the Project Explorer, right-click your client project's WSDL file, and then select WebLogic Web Services > Generate Web Service Client from the drop-down menu, as Figure 1 shows. This will open the New Web Service Client dialog that Figure 2 shows.

What is a WSDL client?

WSDL is an XML notation for describing a web service. A WSDL definition tells a client how to compose a web service request and describes the interface that is provided by the web service provider.

What is Web services client?

A web service is any piece of software that makes itself available over the internet and uses a standardized XML messaging system. XML is used to encode all communications to a web service. For example, a client invokes a web service by sending an XML message, then waits for a corresponding XML response.


2 Answers

As hinted in a comment to Jon's answer, my recommendation would be to use a JAX-WS implementation like JAX-WS RI (which is included in Java 6) or Apache CXF.

I'll use JAX-WS RI to illustrate my answer as it's available out of the box, on the command line (to explain the steps) but I'd recommend using an IDE with good JAX-WS support e.g. NetBeans (see the resources at the end of the answer).

1. Generate JAX-WS artifacts from the WSDL

First run wsimport to generate JAX-WS artifacts (to put it simply, the classes you'll need to invoke the web service):

wsimport -d generated -extension -keep -p com.gatewayedi.ws -XadditionalHeaders https://testservices.gatewayedi.com/PayerList/payerlist.asmx?wsdl  

About the options:

  • -d is used to specify the target directory for the generated stuff
  • -extension is used to allow extensions (the WSDL is using a non-standard SOAP 1.2 binding)
  • -keep is to keep generated .java sources (this is will ease the development)
  • -p is used to specify a package for the generated artifacts
  • -XadditionalHeaders is used to map additional WSDL headers (that are not part of the input or output contract defined in the portType operation) to method parameters (this will make invoking the service easier).

Sorry if some of the vocabulary is cryptic but, well, welcome to SOAP web services :)

2. Implement a client

Here is a simple client showing how to invoke one of the available operations using the generated classes:

import com.gatewayedi.ws.AuthSOAPHeader; import com.gatewayedi.ws.PayerList; import com.gatewayedi.ws.PayerListSoap;  public class Main {      public static void main(String[] args) {         new Main().callWebService();     }      private void callWebService() {         PayerList service = new PayerList();         PayerListSoap port = service.getPayerListSoap();          AuthSOAPHeader authSOAPHeader = new AuthSOAPHeader();         authSOAPHeader.setUser("test");         authSOAPHeader.setPassword("test");          String payerList = port.ping(authSOAPHeader);          System.out.println(payerList);     }  } 

Below, the generated request:

<?xml version="1.0"  standalone="no"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Header> <AuthSOAPHeader xmlns="https://ws.gatewayedi.com/"> <User>test</User> <Password>test</Password> </AuthSOAPHeader> </S:Header> <S:Body> <Ping xmlns="https://ws.gatewayedi.com/"/> </S:Body> </S:Envelope> 

Don't know what credentials you're supposed to pass though.

Resources

  • Developing JAX-WS Web Service Clients (start here)
  • Introducing JAX-WS 2.0 With the Java SE 6 Platform, Part 1
  • Creating a Simple Web Service and Client with JAX-WS
  • Creating a SOAP client with either Apache CXF or GlassFish Metro (Glen Mazza's blog is a great resources)

Related questions

  • Java Webservice Client (Best way)
  • What is the best java webservice framework?
like image 77
Pascal Thivent Avatar answered Sep 22 '22 14:09

Pascal Thivent


EDIT: As Pascal appears to have recent experience on this, it's probably worth reading his comment:

Nowadays, I wouldn't use Axis (I actually recommend against using it). Apache CXF or JAX-WS RI (which is included in Java 6 and offers wsimport and wsgen command line commands) are IMO much better stacks and easier to use.

So, look at the Apache CXF documentation and the introduction to JAX-WS.


Original answer

Have you tried using Apache Axis? It's a while since I've done any Java web services, but that was what I used last time... You'll want to look at WSDL2Java to generate code from the WSDL.

like image 30
Jon Skeet Avatar answered Sep 20 '22 14:09

Jon Skeet