当前位置:编程学习 > C#/ASP.NET >>

关于AXIS2 调用WCF的问题

大家好,我使用AXIS2 调用WCF的时候遇到了如下的错误:
Exception in thread "main" org.apache.axis2.AxisFault: Must Understand check failed for header http://www.w3.org/2005/08/addressing : Action

我通过两种方法调用都是一样的错误,axis2的工具生成的方法以及手写的方法,手写的方法如下:
package ws;

import javax.xml.namespace.QName;

import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.AddressingConstants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.addressing.RelatesTo;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;


public class WebServiceTest {

/**
 * @param args
 */
public static void main(String[] args)throws AxisFault  {
Object[] opAddEntryArgs = new Object[] {"100000260032","4832"};
//         String url="http://r2-sv0038.connecteast.local/ETollingPortal2AbstractionServiceIVR/AccountBalance.svc?wsdl";
        String url="http://r2-sv0038.connecteast.local/ETollingPortal2AbstractionServiceIVR/AccountBalance.svc";
        //url="http://www.w3.org/2005/08/addressing/anonymous.";
       String method="GetAccountBalance1";
       WebServiceTest.sendService(opAddEntryArgs,url,method);
    }
    public static String sendService(Object[] opAddEntryArgs,String url,String method) throws AxisFault{
       String xml=null;
      
           RPCServiceClient serviceClient = new RPCServiceClient();
           //serviceClient.engageModule(new javax.xml.namespace.QName( org.apache.axis2.Constants.MODULE_ADDRESSING ) );
           Options options = serviceClient.getOptions();
           //这里设置使用soap1.2,wcf用的是wshttpbinding 使用的也是soap1.2 貌似axis默认使用soap1.1。
                    //否则会报Exception in thread "main" org.apache.axis2.AxisFault: Transport error: 415 Error: 
                    //Cannot process the message because the content type 'text/xml; charset=UTF-8' 
                    //was not the expected type 'application/soap+xml; charset=utf-8'.的错误
           options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);// 

           EndpointReference targetEPR = new EndpointReference(url);
           options.setTo(targetEPR);
           options.setTimeOutInMilliSeconds((long)600000);
           //options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE); 
           
           // 在创建QName对象时,QName类的构造方法的第一个参数表示WSDL文件的命名空间名,也就是<wsdl:definitions>元素的targetNamespace属性值
            QName opAddEntry = new QName("http://tempuri.org/",method);
            // 参数,如果有多个,继续往后面增加即可,不用指定参数的名称
            ////Object[] opAddEntryArgs = new Object[] {xmlStr};
                      // 返回参数类型,这个和axis1有点区别
            // invokeBlocking方法有三个参数,其中第一个参数的类型是QName对象,表示要调用的方法名;
            // 第二个参数表示要调用的WebService方法的参数值,参数类型为Object[];
            // 第三个参数表示WebService方法的返回值类型的Class对象,参数类型为Class[]。
            // 当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{}
            // 如果被调用的WebService方法没有返回值,应使用RPCServiceClient类的invokeRobust方法,
            // 该方法只有两个参数,它们的含义与invokeBlocking方法的前两个参数的含义相同
            Class[] classes = new Class[] { String.class };
            xml=(String)serviceClient.invokeBlocking(opAddEntry,opAddEntryArgs, classes)[0];
            System.out.println(xml); 
        return xml;
    }


}

  --------------------编程问答-------------------- 另外我在http://blogs.msdn.com/b/aszego/archive/2010/06/24/usernametoken-profile-vs-wcf.aspx 看到这样一段话  没太理解啊。。

Interoperability with Axis
In the actual scenario I wrote this custom token for, the Java-based service didn’t like the addressing headers that WCF generated. In particular, the wsa:Action header had mustUnderstand set to true, and we got the error message that “Must Understand check failed for header http://www.w3.org/2005/08/addressing : Action”.
WCF doesn’t allow removing mustUnderstand from the addressing headers (unless you remove it from the serialized message). Therefore, in the sample I simply ask WCF to not add the addressing headers by setting MessageVersion to Soap11. --------------------编程问答-------------------- 除 --------------------编程问答-------------------- webservice啊webservice,不是说跨平台么  你这是肿么了~~ --------------------编程问答-------------------- --------------------编程问答-------------------- 我也遇到这这个错。请问你解决了嘛? --------------------编程问答--------------------
引用 5 楼 u010795216 的回复:
我也遇到这这个错。请问你解决了嘛?

这之后还遇见很多问题,都忘了专门解决这个问题的办法了。最后好用的配置如下,需要在lib里添加addressing.mar的包


TripPassServiceStub tpss=new TripPassServiceStub();
tpss._getServiceClient().engageModule("addressing");
tpss._getServiceClient().getOptions().setProperty(AddressingConstants.WS_ADDRESSING_VERSION, org.apache.axis2.addressing.AddressingConstants.Final.WSA_NAMESPACE);
int setWebServiceTimeOutInSeconds=mySession.getVariable(IProjectVariables.SET_WEB_SERVICE_TIME_OUT_IN_SECONDS).getSimpleVariable().getIntValue();
tpss._getServiceClient().getOptions().setTimeOutInMilliSeconds(setWebServiceTimeOutInSeconds*1000);
tpss._getServiceClient().getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT,true); 
tpss._getServiceClient().getOptions().setProperty(HTTPConstants.CHUNKED, "false");//设置不受限制.
补充:.NET技术 ,  Web Services
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,