CXF Web服务客户端 - 调用Web服务时未收到数据

CXF Web服务客户端 - 调用Web服务时未收到数据

问题描述:

我已经创建了一个客户端,使用maven和CXF访问WS,请参阅教程herehere as well。 我已经使用SoapUI测试了多次Web服务并收到了结果。但是当我从客户端调用相同的Web服务时,我总是得到一个空的响应。在Web服务方面,我观察到响应正确发送,以防SoapUI和我的客户端应用程序都发送。CXF Web服务客户端 - 调用Web服务时未收到数据

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

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

代码块从的Servlet中的init的Web服务桩模块()方法调用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> 

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

这样做的一种方法是发送日志拦截器。

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

+0

感谢您的回复。我也检查了TCPMon的请求和响应,并找到了与在SoapUI中相同的行为。看起来这是一个在CXF客户端解组响应的问题。有没有办法拦截解组过程? –

+0

服务器如何实现 - 是否也使用CXF。 – gkamal

+0

Web服务是在Tomcat7上运行的JAX-WS实现。早些时候,它是一个Tomcat上的CXF Web服务,但那也不起作用。 –