我使用的是基於IIS的基於SOAP的服務中的Axis2 Wsdl2java。我先設置了requestHeader,然後嘗試在客戶端執行Create方法,該方法接受兩個參數payload xml作爲OMElement和requesType作爲字符串,但獲取如下所示的異常。嘗試執行axis2服務客戶端時出現異常
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");
}
}
}
請格式化您的代碼 – Hilikus