2013-04-02 68 views
1

我有一個在我的計算機上運行的CXF開發的測試webservice,我一直試圖使Apache Axis2的「wsdl2java」功能成爲客戶端。我已經生成的代碼,但我有以下錯誤:Axis2 WebService客戶端:給定的SOAPAction與操作不匹配

org.apache.axis2.AxisFault: The given SOAPAction http://service.taller1.webservices.spring.com/HolaMundoService/saludaHola does not match an operation. 
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531) 
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375) 
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421) 
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) 
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) 
at com.spring.webservices.taller1.service.impl.HolaMundoServiceImplServiceStub.saludaHola(HolaMundoServiceImplServiceStub.java:182) 
at mian.Main.main(Main.java:27) 

這裏的wsdl:

<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://impl.service.taller1.webservices.spring.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://service.taller1.webservices.spring.com/" name="HolaMundoServiceImplService" targetNamespace="http://impl.service.taller1.webservices.spring.com/"> 
    <wsdl:import location="http://localhost:8080/webservice-cfx-spring-0.0.1-SNAPSHOT/HolaMundoService?wsdl=HolaMundoService.wsdl" namespace="http://service.taller1.webservices.spring.com/"> 
    </wsdl:import> 
    <wsdl:binding name="HolaMundoServiceImplServiceSoapBinding" type="ns1:HolaMundoService"> 
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
    <wsdl:operation name="saludaHola"> 
     <soap:operation soapAction="" style="document"/> 
     <wsdl:input name="saludaHola"> 
     <soap:body use="literal"/> 
     </wsdl:input> 
     <wsdl:output name="saludaHolaResponse"> 
     <soap:body use="literal"/> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="HolaMundoServiceImplService"> 
    <wsdl:port binding="tns:HolaMundoServiceImplServiceSoapBinding" name="HolaMundoServiceImplPort"> 
     <soap:address location="http://localhost:8080/webservice-cfx-spring-0.0.1-SNAPSHOT/HolaMundoService"/> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

我希望得到任何幫助。在此先感謝您的幫助!

回答

2

您可能使用了錯誤的操作或錯誤的模式綁定。

下可以爲你工作:

ServiceClient client = new ServiceClient(); 
    OperationClient operationClient = client.createClient(ServiceClient.ANON_OUT_IN_OP); 

    // creating message context 
    MessageContext outMsgCtx = new MessageContext(); 
    // assigning message context’s option object into instance variable 
    Options opts = outMsgCtx.getOptions(); 
    // setting properties into option 
    opts.setTo(new EndpointReference("http://localhost:8080/webservice-cfx-spring-0.0.1-SNAPSHOT/HolaMundoService")); 
    opts.setAction(""); //your soap action is null 
    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); 
    auth.setUsername("user"); 
    auth.setPassword("pass"); 
    opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); 
    //Create the Soap Factory 
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory(); 
    //Create the request envelope 
    SOAPEnvelope envelope = fac.getDefaultEnvelope(); 
    OMNamespace globalNs = fac.createOMNamespace("http://service.taller1.webservices.spring.com/", "ns1"); 
    // creating the payload 
    OMElement method = fac.createOMElement("saludaHola", globalNs); 
    method.setText("Hello"); 
    envelope.getBody().addChild(method); 
    outMsgCtx.setEnvelope(envelope); 
    operationClient.addMessageContext(outMsgCtx); 
    operationClient.execute(true); 
    MessageContext inMsgtCtx = operationClient.getMessageContext("In"); 
    //get the response 
    SOAPEnvelope response = inMsgtCtx.getEnvelope(); 
    System.out.println(response); 
+0

良好的代碼來演示消息構建是如何工作的。你錯過了上下文中的信封(我添加了它) –

相關問題