当前位置:   article > 正文

java调用webservice接口(asmx)_java调用webservice(asmx)

java调用webservice(asmx)

对方提供的接口文档
webservice接口地址:http://192.168.0.16/WebService/CityManagerQYSWGnew.asmx
在这里插入图片描述

import org.apache.axis.client.Call;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;
import org.apache.axis.client.Service;

 public void callWebserviceASMX() throws IOException {
        String caseguid = this.getRequestParameter("caseguid");
        //获取webservice接口地址
        String url = "http://172.20.197.226/WebService/CityManagerQYSWGnew.asmx";
        //获取域名地址,server定义的,一般默认是http://tempuri.org/,如果不对,找对方索要
        String soapaction = "http://tempuri.org/";
        String method = "FNZF_BH_CityManage";
        Service service = new Service();
        String result = "";
        try {
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(url);
            //设置要调用的方法
            call.setOperationName(new QName(soapaction, method));
            // 设置要传递的参数,字符串用XMLType.XSD_STRING,日期用XMLType.XSD_DATE(根据对方要求)
            call.addParameter(new QName(soapaction, "caseguid"), XMLType.XSD_STRING, ParameterMode.IN);
            call.addParameter(new QName(soapaction, "status"), XMLType.XSD_STRING, ParameterMode.IN);
            call.addParameter(new QName(soapaction, "reason"), XMLType.XSD_STRING, ParameterMode.IN);
            call.addParameter(new QName(soapaction, "ValidateData"), XMLType.XSD_STRING, ParameterMode.IN);
            //设置要返回的数据类型(标准的类型)
            call.setReturnType(XMLType.XSD_STRING);
            call.setUseSOAPAction(true);
            call.setSOAPActionURI(soapaction + method);
            //调用方法并传递参数
            result = (String) call.invoke(new Object[]{caseguid, "E", "作废理由", "FNZF_**##"});
            System.out.println("result is:::" + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        this.getResponse().getWriter().println(result);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37

调用域名及调用方法名是在server端SOAPAction配置

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

<?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>
    <FNZF_BH_CityManage xmlns="http://tempuri.org/">
      <caseguid>string</caseguid>
      <status>string</status>
      <reason>string</reason>
      <ValidateData>string</ValidateData>
    </FNZF_BH_CityManage>
  </soap:Body>
</soap:Envelope>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/798104
推荐阅读
相关标签
  

闽ICP备14008679号