代码改变世界

使用axis2访问webservice(webserivice基于.net平台实现)

2015-10-12 10:37  JerremyZhang  阅读(749)  评论(0编辑  收藏  举报

webservice url=http://10.90.11.240:8081/ExceptionWebService.asmx?WSDL;

下载axis2组件,解压,进入bin目录,通过命令wsdl2java -uri http://10.90.11.240:8081/ExceptionWebService.asmx?WSDL -p com.zsp.proxy -s -o source

-uri 后面运行的是 你的wsdl地址, -p 是文件生成的包名 -o source生成的文件目录,在bin目录下。

把生成的代理类,拷贝到你的工程目录中,导入对应的包即可访问:

例如

POST /ExceptionWebService.asmx HTTP/1.1
Host: 10.90.11.240
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/ApproveException"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ApproveException xmlns="http://tempuri.org/">
      <eventName>string</eventName>
      <description>string</description>
      <occurTime>string</occurTime>
      <livingPlace>string</livingPlace>
      <eventLevel>一般 or 急件 or 紧急 or 特急</eventLevel>
      <bussinessCategory>运销 or 管道 or 设备 or HSE or 经营 or 管理 or 工程 or 科技 or 信息 or 党群 or 其它</bussinessCategory>
      <reporterId>string</reporterId>
      <contact>string</contact>
      <systemId>string</systemId>
      <businessPK>string</businessPK>
      <remark>string</remark>
      <isRelease>boolean</isRelease>
      <measures>string</measures>
    </ApproveException>
  </soap:Body>
</soap:Envelope>

访问时:

public class Test2 {

    public static void main(String[] args) throws RemoteException {
        // TODO Auto-generated method stub
        ExceptionServiceStub proxy = new ExceptionServiceStub();

        ExceptionServiceStub.ApproveException exp = new ExceptionServiceStub.ApproveException();
        exp.setContact("374378");
        exp.setDescription("描述");
        exp.setEventName("测试异常");
        exp.setIsRelease(true);
        exp.setLivingPlace("发生地点");
        exp.setMeasures("47477474");
        exp.setOccurTime("2019-09-09");
        exp.setSystemId("xj_001");
        exp.setRemark("备注");
        exp.setEventLevel(EmergencyDegree.一般);
        exp.setBussinessCategory(BusinessCategory.HSE);
        exp.setBusinessPK("bpk");
        exp.setReporterId("xxxx");
        ApproveExceptionResponse res = proxy.approveException(exp);
        System.out.println(res.getApproveExceptionResult());
    }

}

使用内部类的方式设置参数,很方便,这种方式和C#通过VS生成代理的操作方式基本一致。

客户端需要导入的包如下: