• 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 }
  • 相关阅读:
    (萌O(∩_∩)O)哈希知识点小结
    hash应用以及vector的使用简介:POJ 3349 Snowflake Snow Snowflakes
    BestCoder Round #3HDU 4907
    搜索:POJ2251&POJ1426&POJ3087&POJ2488
    母函数初学四大题
    欧拉函数知识点总结及代码模板及欧拉函数表
    欧几里德与扩展欧几里德算法以及青蛙的约会~
    KMP 知识点总结
    HDU 1142 A Walk Through the Forest(dijkstra+记忆化DFS)
    HDU 1535 Invitation Cards(SPFA,及其优化)
  • 原文地址:https://www.cnblogs.com/jeffreyluo/p/5236074.html
Copyright © 2020-2023  润新知