2012-08-31 42 views
4

我是使用jax-ws的web服務新手。我開始基於Web上的某種教程來實現它。此外,我試圖通過我的Android客戶端訪問該服務,所以我打電話給這個。給定的SOAPAction與操作不匹配

private static final String SOAP_ACTION = "http://service.my/sayHello"; 
    androidHttpTransport.call(SOAP_ACTION, envelope); 

但是當我嘗試printstacktrace時出現此錯誤。

WARNING: Interceptor for {http://service.my/}HelloServiceImplService#{http://service.my/}sayHello has thrown exception, unwinding now 
org.apache.cxf.interceptor.Fault: The given SOAPAction http://service.my/sayHello does not match an operation. 
    at org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor$SoapActionInAttemptTwoInterceptor.handleMessage(SoapActionInInterceptor.java:188) 
    at org.apache.cxf.binding.soap.interceptor.SoapActionInInterceptor$SoapActionInAttemptTwoInterceptor.handleMessage(SoapActionInInterceptor.java:162) 
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) 
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) 
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207) 
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:209) 
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:191) 
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:114) 
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185) 
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641) 
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:164) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 

這是我的WSDL的方式:

<wsdl:definitions xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.my/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HelloServiceImplService" targetNamespace="http://service.my/"> 
<wsdl:types> 
<xs:schema xmlns:tns="http://service.my/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" targetNamespace="http://service.my/" version="1.0"> 
<xs:element name="sayHello" type="tns:sayHello"/> 
<xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/> 
<xs:complexType name="sayHello"> 
<xs:sequence> 
<xs:element minOccurs="0" name="arg0" type="xs:string"/> 
</xs:sequence> 
</xs:complexType> 
<xs:complexType name="sayHelloResponse"> 
<xs:sequence> 
<xs:element minOccurs="0" name="return" type="xs:string"/> 
</xs:sequence> 
</xs:complexType> 
</xs:schema> 
</wsdl:types> 
<wsdl:message name="sayHelloResponse"> 
<wsdl:part element="tns:sayHelloResponse" name="parameters"></wsdl:part> 
</wsdl:message> 
<wsdl:message name="sayHello"> 
<wsdl:part element="tns:sayHello" name="parameters"></wsdl:part> 
</wsdl:message> 
<wsdl:portType name="HelloService"> 
<wsdl:operation name="sayHello"> 
<wsdl:input message="tns:sayHello" name="sayHello"></wsdl:input> 
<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse"></wsdl:output> 
</wsdl:operation> 
</wsdl:portType> 
<wsdl:binding name="HelloServiceImplServiceSoapBinding" type="tns:HelloService"> 
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="sayHello"> 
<soap:operation soapAction="" style="document"/> 
<wsdl:input name="sayHello"> 
<soap:body use="literal"/> 
</wsdl:input> 
<wsdl:output name="sayHelloResponse"> 
<soap:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="HelloServiceImplService"> 
<wsdl:port binding="tns:HelloServiceImplServiceSoapBinding" name="HelloServiceImplPort"> 
<soap:address location="http://192.168.0.102:8080/TestWS/myService"/> 
</wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 

回答

2

SOAP行動應該是這樣的:{http://service.my/}sayHello如果指定這樣的:http://service.my/sayHelloCXF不明白,這是一個動作,這看起來更像是一個名字空間,而不是一個動作。

更改此:

private static final String SOAP_ACTION = "http://service.my/sayHello"; 

到這一點:

private static final String SOAP_ACTION = "{http://service.my/}sayHello"; 

,它應該工作。

13

根據您的WSDL:

<soap:operation soapAction="" style="document"/> 

的SOAPAction的應該是一個空字符串,而不是 「http://service.my/sayHello」。

1

當使用CXF JAX-WS時,遇到類似「給定SOAPAction ...與操作不匹配」的問題。 如果你使用如下

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); 
factory.setAddress(endpointAddress); 
XXXServicePortType port = factory.create(XXXServicePortType.class); 
// (set HTTP header here) 
port.someMethod() 

它是由HTTP標頭「的SOAPAction」引起了JAX-WS代理不能設置爲「」 你可以通過設置它下面的代碼:地方臺(套HTTP標頭在這裏)

org.apache.cxf.endpoint.Client proxy = ClientProxy.getClient(port); 
Map<String, List<String>> headers = new HashMap<String, List<String>>(); 
headers.put("SOAPAction", Arrays.asList("")); 
proxy.getRequestContext().put(Message.PROTOCOL_HEADERS, headers); 
相關問題