webService 客户端调用及异常信息First Element must contain the local name, Envelope , but found definitions(示例代

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webService 客户端调用及异常信息First Element must contain the local name, Envelope , but found definitions(示例代相关的知识,希望对你有一定的参考价值。

报错:“First Element must contain the local name, Envelope , but found definitions”;

 

原因:EndpointReference end = new EndpointReference(url) ,url错误;

 

源代码:

 1 import org.apache.axiom.om.OMAbstractFactory;
 2 import org.apache.axiom.om.OMElement;
 3 import org.apache.axiom.om.OMFactory;
 4 import org.apache.axiom.om.OMNamespace;
 5 import org.apache.axis2.AxisFault;
 6 import org.apache.axis2.addressing.EndpointReference;
 7 import org.apache.axis2.client.Options;
 8 import org.apache.axis2.client.ServiceClient;
 9 
10 public class Test {
11     public static void main(String[] args) throws AxisFault {
12         OMElement element = test("22","444","123");
13         System.out.println(element.getText());
14     }
15     
16     private static OMElement test(String contractNo, String contractName, String auditMoney) throws AxisFault {
17         OMFactory factory = OMAbstractFactory.getOMFactory();
18         OMNamespace ns1 = factory.createOMNamespace("http://wwww.test.com/UpdateContractDeductMoneySrv/", "upd");
19         OMNamespace ns = factory.createOMNamespace("", "");
20         OMElement result;
21         ServiceClient sc = new ServiceClient();  
22         Options opts = sc.getOptions();   
23  //       String url = "http://localhost:8989/test/services/UpdateContractAuditMoneySrv?wsdl";  //错误
24         String url = "http://localhost:8989/test/services/UpdateContractDeductMoneySrv";  //正确
25         EndpointReference end = new EndpointReference(url); 
26         OMElement method = factory.createOMElement("UpdateMoneyCollection", ns);
27         OMElement param = factory.createOMElement("ContractNo", ns);
28         param.setText(contractNo);
29         method.addChild(param);
30         param = factory.createOMElement("ContractName", ns);
31         param.setText(contractName);
32         method.addChild(param);
33         param = factory.createOMElement("AuditMoney", ns);
34         param.setText(auditMoney);
35         method.addChild(param);
37         param = factory.createOMElement("Items", ns);
38             OMElement newOperation = factory.createOMElement("NewOperation1", ns1);
39             param.addChild(newOperation);
40             OMElement contractLineNo = factory.createOMElement("ContractLineNo", ns);
41             contractLineNo.setText("1");
42             newOperation.addChild(contractLineNo);
43             OMElement lineAuditMoney = factory.createOMElement("LineAuditMoney", ns);
44             lineAuditMoney.setText("23");
45             newOperation.addChild(lineAuditMoney);
46 
47         method.addChild(param);
48         method.build();
49         System.out.println("method==="+method.toString());
50         try {
51             sc.setTargetEPR(end);
52             result = sc.sendReceive(method);
53         } catch (AxisFault axisFault) {
54             result = factory.createOMElement("return", ns);
55             OMElement flag = factory.createOMElement("flag", ns);
56 //            flag.setText(Integer.toString(ERROR));
57             result.addChild(flag);
58             OMElement message = factory.createOMElement("message", ns);
59             message.setText(axisFault.getReason());
60             result.addChild(message);
61             System.out.println("result = " + result);
62         }
63         System.out.println("result = " + result);
64         return result;
65     }
66 }

 

以上是关于webService 客户端调用及异常信息First Element must contain the local name, Envelope , but found definitions(示例代的主要内容,如果未能解决你的问题,请参考以下文章

关于在VS2010中调用Webservic遇到的异常

java axis2 调用webservice 怎么捕获超时异常(即超时了让它停下来,不要报错)

webservice客户端调用服务端异常 —— 远程主机强迫关闭了一个现有的连接

springmvc调用webservice线上异常

wsdl的web服务怎么调用

使用xfire客户端调用CXF的服务时,出现空指针异常。