JavaがWebサービスインターフェイス(asmx)を呼び出す

相手側から提供されたインターフェイスドキュメントの
Webサービスインターフェイスアドレス: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);
    }

呼び出しドメイン名と呼び出しメソッド名はサーバー側の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>
19件のオリジナル記事を掲載 いいね2 訪問数721

おすすめ

転載: blog.csdn.net/qq_40977118/article/details/104883366