Web服务客户端给出了WSDL

时间:2010-11-13 10:47:59

标签: java web-services wsdl webservice-client

我正在尝试用Java创建一个Web服务客户端。我不知道该怎么做。这是WSDL的URL:https://testservices.gatewayedi.com/PayerList/payerlist.asmx?wsdl

这是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>

服务中有三种方法。

我正在尝试使用SOAP调用此方法。

XML消息格式为:

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> 

任何知道解决方案的人都请告诉我。 任何帮助都非常明显。

4 个答案:

答案 0 :(得分:51)

正如对Jon's answer的评论中暗示的那样,我的建议是使用JAX-WS实现,如JAX-WS RI(包含在Java 6中)或Apache CXF。

我将使用JAX-WS RI来说明我的答案,因为它可以在命令行中开箱即用(解释步骤),但我建议使用具有良好JAX-WS支持的IDE,例如: NetBeans(请参阅答案末尾的资源)。

1。从WSDL

生成JAX-WS工件

首先运行wsimport来生成JAX-WS工件(简单来说,就是调用Web服务所需的类):

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

关于选项:

很抱歉,如果某些词汇表含糊不清,欢迎使用SOAP Web服务:)

2。实现客户端

这是一个简单的客户端,展示了如何使用生成的类调用其中一个可用操作:

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);
    }

}

下面是生成的请求:

<?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>

不知道你应该传递什么凭据。

资源

相关问题

答案 1 :(得分:3)

编辑:由于Pascal似乎最近有过这方面的经验,所以值得一读他的评论:

  

如今,我不会使用Axis(我实际上建议不要使用它)。 Apache CXF或JAX-WS RI(包含在Java 6中并提供wsimport和wsgen命令行命令)是IMO更好的堆栈并且更易于使用。

因此,请查看Apache CXF documentationintroduction to JAX-WS


原始回答

您是否尝试过使用Apache Axis?我已经有一段时间了,因为我已经完成了任何Java Web服务,但这是我上次使用的...你会想看看WSDL2Java从WSDL生成代码。

答案 2 :(得分:2)

除了上面提到的内容之外,您还可以使用诸如Netbeans之类的IDE。它基本上允许您通过向导创建Web服务客户端,而无需自己完成所有配置。 This视频向您展示了如何首先创建Web服务,然后如何创建其相应的客户端。请注意,在视频中,无论谁在做教程,都会通过其他Web应用程序使用Web服务。如果您想通过桌面应用程序使用Web服务,只需执行相同的过程,唯一的区别是您在正在处理的项目上执行此操作而不是Web项目。

答案 3 :(得分:1)

我建议看一下Apache Axis2 org Apache WSIF(Web服务调用框架)。

链接: