• 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 }
  • 相关阅读:
    1 slow requests are blocked > 32 sec解决方法
    centos7下搭建ceph luminous(12.2.1)--无网或网络较差
    防止集群数据恢复设置
    ceph:health_warn clock skew detected on mon的解决办法
    Windows下判断jdk是否安装好以及环境变量是否配置好
    卸载Myeclipse10.5 报错“an error has occured.See the log file ...Uninstaller...”
    转: Laravel 自定义公共函数的引入
    windows下安装composer
    PHP与.Net的区别(一)接口
    phpStorm+XDebug配置
  • 原文地址:https://www.cnblogs.com/jeffreyluo/p/5236074.html
Copyright © 2020-2023  润新知