java - 如何使用 AXis 1.4 创建 Java 客户端以使用 wsHttpBinding 使用 WCF 服务

标签 java wcf client axis

我创建了一个 java 客户端,用于使用 axis 1.4 使用 WCF 服务。如果我使用 basicHttpBinding 则一切正常,但如果我使用 wsHttpBinding 则出现以下错误:-

Did not understand "MustUnderstand" header(s):{http://www.w3.org/2005/08/addressing}Action
AxisFault
 faultCode: {http://www.w3.org/2003/05/soap-envelope}MustUnderstand
 faultSubcode: 
 faultString: Did not understand "MustUnderstand" header(s):{http://www.w3.org/2005/08/addressing}Action
 faultActor: 
 faultNode: 
 faultDetail: 
    {http://xml.apache.org/axis/}stackTrace:
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:96)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at org.tempuri.WSHttpBinding_IService1Stub.getData(WSHttpBinding_IService1Stub.java:171)
    at Mytes.main(Mytes.java:14)

    {http://xml.apache.org/axis/}hostname:2207A-H7-SITA

Did not understand "MustUnderstand" header(s):{http://www.w3.org/2005/08/addressing}Action
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:96)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
    at org.apache.axis.client.Call.invoke(Call.java:2767)
    at org.apache.axis.client.Call.invoke(Call.java:2443)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at org.tempuri.WSHttpBinding_IService1Stub.getData(WSHttpBinding_IService1Stub.java:171)
    at Mytes.main(Mytes.java:14)

请告诉我如何解决此错误。谢谢。

最佳答案

当您使用 Axis 为 WCF 服务生成代理时,它会生成自动为 http://www.w3.org/2005/08/设置 MustUnderstand header 的 stub 寻址

下面的代码将 MustUnderstand 标志重置为 false。对于被调用的方法。我今天遇到了类似的问题,并且能够使用此处发布的代码解决

//maybe someother service stub,i show you a case
    CommentWcfServiceLocator locator =new CommentWcfServiceLocator();
    WSHttpBinding_ICommentServiceStub stub;
    try {       
    //get a stub and set service url
    stub = (WSHttpBinding_ICommentServiceStub)   locator.getWSHttpBinding_ICommentService(new         java.net.URL("http://www.google.com/CommentWcfService.svc"));

    // the key is here , importantest!!! follow this
    // set action, action path,you can find in your java code
    SOAPHeaderElement action = new SOAPHeaderElement(new QName("wsa:Action"),     "http://tempuri.org/ICommentService/GetCommentSummaryByHotelId");
    SOAPHeaderElement to = new SOAPHeaderElement(new QName("wsa:To"),
    stub._getProperty(javax.xml.rpc.Stub.ENDPOINT_ADDRESS_PROPERTY));
        action.setActor(null);
        action.setNamespaceURI("http://www.w3.org/2005/08/addressing");
        to.setActor(null);
        to.setNamespaceURI("http://www.w3.org/2005/08/addressing");
         // set header
                stub.setHeader(action);
        stub.setHeader(to);
                // must set this property
        stub._setProperty(Call.CHECK_MUST_UNDERSTAND, Boolean.FALSE);
            stub.getCommentSummaryByHotelId("","02201158", 0);
    } 
catch(Exception EX){}

我找到了 this post关于 MustUnderstand 非常有帮助。

关于java - 如何使用 AXis 1.4 创建 Java 客户端以使用 wsHttpBinding 使用 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3299075/

相关文章:

java套接字输入流,PrintWriter不工作

c++ - 使用 C++ 读取 Cookie(客户端)

jar - 在 Java 中重新打包库 JAR

java - 按列打印 Java 数组

java - JSP 类文件到 HTML

c# - 服务器在 CPU 负载过重或线程池繁忙时出现 WCF 可靠 session 故障

wpf - 将 Checkbox IsChecked 绑定(bind)到 EntityFramework 在 MVVM 模式中不起作用

wcf - 修改后的WCF消息正文显示<s:Body>…流…</s:Body>

spring - 向所有传出 CXF 请求添加 header

java - 如何从 xml 响应中检索字段