Java 尝试执行axis2服务客户端时发生异常

Java 尝试执行axis2服务客户端时发生异常,java,web-services,soap,axis2,Java,Web Services,Soap,Axis2,我使用的是托管在IIS上的基于SOAP的服务中的Axis2 Wsdl2java。我首先设置了requestHeader,然后尝试在客户机中执行Create方法,该方法接受两个参数:负载xml作为OmeElement,RequestType作为字符串,但得到的异常如下所示 org.apache.axis2.AxisFault: System.Web.Services.Protocols.SoapException: Server was unable to process request. --

我使用的是托管在IIS上的基于SOAP的服务中的Axis2 Wsdl2java。我首先设置了requestHeader,然后尝试在客户机中执行Create方法,该方法接受两个参数:负载xml作为OmeElement,RequestType作为字符串,但得到的异常如下所示

org.apache.axis2.AxisFault: System.Web.Services.Protocols.SoapException: Server was  unable to process request. ---> System.InvalidCastException: Unable to cast object of type 'System.Xml.XmlNode[]' to type 'System.String'.
有人能帮我理解下面代码的问题吗?或者为什么我会遇到上面的异常

请参见以下我的客户代码:

 package net.approva.BizRights.Services;

 public class Client{
    public static void main(java.lang.String args[]){
    try
    {
       ApprovalRequestManagerStub stub =
       new ApprovalRequestManagerStub("serverurl.asmx");            
       Create(stub);     
    } 
    catch(Exception e)
    {
       e.printStackTrace();
       System.out.println("\n\n\n");
    }
    }
    /* Create */
    public static void Create(ApprovalRequestManagerStub stub){
        try
        {            
            net.approva.BizRights.Services.ApprovalRequestManagerStub.Create req = new Create();            

            java.lang.String content = "<approvalrequests xmlns=\"http://www.approva.net/ApprovalRequest.xsd\"><approvalrequest><name>USER  002371(ABC)</name><type>OnlyWhatIfAnalysis</type><status>SubmittedForWhatIf</status><priority>Medium</priority><applicationid>2</applicationid><applicationname>SAP AI Connection</applicationname><format>NoConstraints</format><requestdetails><roleassignment><users><user><id>591</id><userid>ABC</userid><lastname>002371</lastname><firstname>USER</firstname><validfromdate>1900-01-01</validfromdate><validtodate>1900-01-01</validtodate></user></users><roles><role revoke=\"false\"><id>3172</id><name>SAP_ICM_S_CUST</name><fromdate>1900-01-02T00:00:00</fromdate><todate>1900-01-01T00:00:00</todate><roletype>4</roletype><description>Commissions: Customizing</description></role></roles></roleassignment><applicationscope><scope displaytext=\"Application\" name=\"firstlevelscope\"><scopevalue displaytext=\"SAP AI Connection\">SAP AI Connection</scopevalue></scope></applicationscope><comment /><asanotheruser /><requestor><id>1</id><userid>administrator</userid></requestor><whatifliveverify>1</whatifliveverify><analysisresults /></requestdetails><requestor><lastname /><firstname /><displayname>administrator</displayname></requestor><applicationscope><scope name=\"firstlevelscope\"><scopevalue>SAP AI Connection</scopevalue></scope></applicationscope><liveverify>1</liveverify></approvalrequest></approvalrequests>";

                                                org.apache.axiom.om.OMFactory fac = org.apache.axiom.om.OMAbstractFactory.getOMFactory();
                                                org.apache.axiom.om.OMNamespace omNs = fac.createOMNamespace("http://www.approva.net/BizRights/Services", null);                                              
                                                org.apache.axiom.om.OMElement _valueObjXML = fac.createOMElement("approvalrequests", omNs);                                                
                                                _valueObjXML.addChild(fac.createOMText(_valueObjXML, content));                          

                                                req.setObjXML(_valueObjXML);                                       

                                                System.out.println(_valueObjXML.getText());                                              

            req.setObjType(WellKnownType.ApprovalRequest);

            BRSoapHeader brSOAP =  new BRSoapHeader();
            brSOAP.setProfileID(1);
            brSOAP.setCallingModuleName(null);
            brSOAP.setOpDocumentationXML(null); 

            BRSoapHeaderE brSoapHeader = new BRSoapHeaderE();
            brSoapHeader.setBRSoapHeader(brSOAP);       

            net.approva.BizRights.Services.ApprovalRequestManagerStub.CreateResponse res = new CreateResponse();
            res = stub.create(req, brSoapHeader);         

            System.out.println(res.toString());
            System.out.println("Request Creation done using Axis2");
        } catch(Exception e){
            e.printStackTrace();
            System.out.println("\n\n\n");
        }
    }


}
package net.approva.BizRights.Services;
公共类客户端{
公共静态void main(java.lang.String参数[]){
尝试
{
ApprovalRequestManagerStub=
新的ApprovalRequestManagerStub(“serverurl.asmx”);
创建(存根);
} 
捕获(例外e)
{
e、 printStackTrace();
System.out.println(“\n\n\n”);
}
}
/*创造*/
公共静态void创建(ApprovalRequestManagerStub){
尝试
{            
net.approva.BizRights.Services.ApprovalRequestManagerStub.Create req=new Create();
java.lang.String content=“用户002371(ABC)仅为什么媒体2 SAP AI连接提交分析无培训591ABC002371用户1900-01-011900-01-013172SAP_ICM_用户1900-01-02T00:00:001900-01-01T00:00:004命令:定制SAP AI连接1管理员1管理员SAP AI连接1”;
org.apache.axiom.om.OMFactory fac=org.apache.axiom.om.OMAbstractFactory.getOMFactory();
org.apache.axiom.om.OMNamespace omNs=fac.createOMNamespace(“http://www.approva.net/BizRights/Services“,空);
org.apache.axiom.om.OMElement _valueObjXML=fac.createOMElement(“批准请求”,omNs);
_addChild(fac.createOMText(_valueObjXML,content));
请求setObjXML(_valueObjXML);
System.out.println(_valueObjXML.getText());
请求setObjType(WellKnownType.ApprovalRequest);
BRSoapHeader brSOAP=新的BRSoapHeader();
brSOAP.setProfileID(1);
brSOAP.setCallingModuleName(null);
brSOAP.setOpDocumentationXML(null);
brSoapHeader brSoapHeader=新的brSoapHeader();
brSoapHeader.setBRSoapHeader(brSOAP);
net.approva.BizRights.Services.ApprovalRequestManagerStub.CreateResponse res=new CreateResponse();
res=stub.create(req,brSoapHeader);
System.out.println(res.toString());
System.out.println(“使用Axis2完成请求创建”);
}捕获(例外e){
e、 printStackTrace();
System.out.println(“\n\n\n”);
}
}
}

首先,您已经在内容字符串声明的这一行包含了approvalrequests标记

java.lang.String content = "<approvalrequests xmlns=\"http://www.approva.net/ApprovalRequest.xsd\"><approvalrequest><name>USER  002371(ABC)</name><type>OnlyWhatIfAnalysis</type><status>SubmittedForWhatIf</status><priority>Medium</priority><applicationid>2</applicationid><applicationname>SAP AI Connection</applicationname><format>NoConstraints</format><requestdetails><roleassignment><users><user><id>591</id><userid>ABC</userid><lastname>002371</lastname><firstname>USER</firstname><validfromdate>1900-01-01</validfromdate><validtodate>1900-01-01</validtodate></user></users><roles><role revoke=\"false\"><id>3172</id><name>SAP_ICM_S_CUST</name><fromdate>1900-01-02T00:00:00</fromdate><todate>1900-01-01T00:00:00</todate><roletype>4</roletype><description>Commissions: Customizing</description></role></roles></roleassignment><applicationscope><scope displaytext=\"Application\" name=\"firstlevelscope\"><scopevalue displaytext=\"SAP AI Connection\">SAP AI Connection</scopevalue></scope></applicationscope><comment /><asanotheruser /><requestor><id>1</id><userid>administrator</userid></requestor><whatifliveverify>1</whatifliveverify><analysisresults /></requestdetails><requestor><lastname /><firstname /><displayname>administrator</displayname></requestor><applicationscope><scope name=\"firstlevelscope\"><scopevalue>SAP AI Connection</scopevalue></scope></applicationscope><liveverify>1</liveverify></approvalrequest></approvalrequests>";

请格式化您的代码我将尝试使用CreateOmeElement的另一个重载删除它,但您认为此异常是由于这行代码造成的吗?调试时,我发现它只发送“内容”XML,而不发送附加的XML。我尝试运行代码,但没有在下面一行,得到了相同的异常。。。。。System.out.println(_valueObjXML.getText());我观察到这种情况的发生是因为OmeElement被序列化为XML而不是字符串,如果有人能帮助理解AXIS2中OmeElement的序列化过程,可以帮助我。。
org.apache.axiom.om.OMElement _valueObjXML = fac.createOMElement("approvalrequests", omNs);