我已按照教程here和here as well创建了一个使用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>
答案 0 :(得分:0)
调试此方法的最简单方法是捕获请求和响应XML。
这样做的一种方法是发送日志记录拦截器。
另一种方法是使用tcpmon捕获请求/响应和响应。 tcpmon就像一个代理 - 将其设置为侦听某个端口,然后将其转发到原始服务主机:port。使客户端向tcpmon端口发送请求。