2

我已经创建了一个客户端来使用 maven 和 CXF 访问 WS,也遵循这里这里的教程。我已经使用 SoapUI 多次测试了 Web 服务并收到了结果。但是,当我从客户端调用相同的 Web 服务时,我总是得到一个空响应。在 Web 服务端,我观察到响应已正确发送,在 SoapUI 和我的客户端应用程序的情况下。这是在客户端控制台上打印的内容:

WS init successful. Service class instantiated.
In servlet Calling service now
Action is -- JAX-WS RI 2.1.6 in JDK 6: Stub for http://172.18.40.131:8080/AccountWithCXF/services/AccountSearchActionPort
In servlet after Calling service. list is -> []

有人可以帮帮我吗?

以下是 WSDL:

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="AccountSearchActionService" targetNamespace="http://webservice/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservice/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://webservice/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<import namespace="http://webservice/" schemaLocation="http://172.18.40.131:8080/AccountWithCXF/services/AccountSearchActionPort?xsd=accountsearchaction_schema1.xsd"/>
</schema>
  </wsdl:types>
  <wsdl:message name="getAccountsResponse">
    <wsdl:part element="tns:getAccountsResponse" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="getAccounts">
    <wsdl:part element="tns:getAccounts" name="parameters">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="AccountSearchAction">
    <wsdl:operation name="getAccounts">
      <wsdl:input message="tns:getAccounts" name="getAccounts">
    </wsdl:input>
      <wsdl:output message="tns:getAccountsResponse" name="getAccountsResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="AccountSearchActionServiceSoapBinding" type="tns:AccountSearchAction">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getAccounts">
      <soap:operation soapAction="urn:GetAccounts" style="document"/>
      <wsdl:input name="getAccounts">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="getAccountsResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="AccountSearchActionService">
    <wsdl:port binding="tns:AccountSearchActionServiceSoapBinding" name="AccountSearchActionPort">
      <soap:address location="http://172.18.40.131:8080/AccountWithCXF/services/AccountSearchActionPort"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

我在我的 servlet 的 init() 方法中设置 Web 服务存根

public void init() throws ServletException {
   super.init();
   service = new AccountSearchActionService();
   System.out.println("WS init successful. Service class instantiated.");
}

Servlet 中调用 Web 服务的代码段:

AccountSearchAction action = service.getAccountSearchActionPort();
System.out.println("Action is -- "+action);
List<Account> list = action.getAccounts(param);
System.out.println("In servlet after Calling service. list is -> "+list);

如果我使用带有搜索查询“express”的 SoapUI 调用此 Web 服务,以下是我得到的响应:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns2:getAccountsResponse xmlns:ns2="http://webservice/">
         <ns2:return>
            <accountId>3067822</accountId>
            <accountName>FBB EXPRESS INC.</accountName>
         </ns2:return>
      </ns2:getAccountsResponse>
   </soap:Body>
</soap:Envelope>
4

1 回答 1

0

最简单的调试方法是捕获请求和响应 XML。

一种方法是发送日志拦截器。

另一种方法是使用 tcpmon 来捕获请求/响应和响应。tcpmon 像代理一样工作 - 将其设置为侦听某个端口,然后将其转发到原始服务主机:端口。使客户端向 tcpmon 端口发送请求。

于 2012-09-13T10:39:08.440 回答