一、要学会看wsdl文件
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">当有第三方开发人员需要获取本呼叫中心系统报表数据时,可通过本Webservice接口快速的获取指定统计指标的数据集。查询结果通过json的方式返回,由第三方开发人员读取解析。</wsdl:documentation>
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="get_report_data">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="strUid" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="strDateTime_start" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="strDateTime_end" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="strKPI_set" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="nType" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="strMem" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="strFilter" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="get_report_dataResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="get_report_dataResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="get_report_dataSoapIn">
<wsdl:part name="parameters" element="tns:get_report_data"/>
</wsdl:message>
<wsdl:message name="get_report_dataSoapOut">
<wsdl:part name="parameters" element="tns:get_report_dataResponse"/>
</wsdl:message>
<wsdl:portType name="OpenReportSoap">
<wsdl:operation name="get_report_data">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">获取报表指标统计。<BR/><B>strUid</B><BR/>可为空<BR/><B>strDateTime_start</B><BR/>开始时间,格式:yyyy-MM-dd[ HH:mm:ss]<BR/><B>strDateTime_end</B><BR/>结束时间,格式:yyyy-MM-dd[ HH:mm:ss]<BR/><B>strKPI_set</B> <font color='red'>※以现场工程师提供为准</font><BR/>指标编号集合,如:201,202,203<BR/><B>nType</B><BR/>维度类型:72(H)-按时统计,68(D)-按日统计,87(W)-按周统计,77(M)-按月统计,85(U)-按座席工号统计 71(G)-按ACD组统计<BR/><B>strMem</B><BR/>对应的成员集合,如座席工号集合:8601;8602;8603 ACD组号集合:1;2;12;13<BR/><B>strFilter</B><BR/>可为空</wsdl:documentation>
<wsdl:input message="tns:get_report_dataSoapIn"/>
<wsdl:output message="tns:get_report_dataSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="OpenReportSoap" type="tns:OpenReportSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="get_report_data">
<soap:operation soapAction="http://tempuri.org/get_report_data" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="OpenReport">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">当有第三方开发人员需要获取本呼叫中心系统报表数据时,可通过本Webservice接口快速的获取指定统计指标的数据集。查询结果通过json的方式返回,由第三方开发人员读取解析。</wsdl:documentation>
<wsdl:port name="OpenReportSoap" binding="tns:OpenReportSoap">
<soap:address location="http://172.16.3.60:8080/ut_report/OpenReport.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
基本顺序是 service-binding-portType-message-types.
我采用的是axis调用,代码如下:
package com.my.webservice;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
public class myWebService {
public static void main(String args[]){
try {
//wsdl:service中soap:address所对应的地址
String endpoint = "http://172.16.3.60:8080/ut_report/OpenReport.asmx?wsdl";
//方法名称,可在wsdl:portType 中wsdl:operation name所对应的名称
String method="get_report_data";
//命名空间,可在wsdl:definitions targetNamespace中找到
String targetNamespace="http://tempuri.org/";
Service service=new Service();
Call call=(Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName(targetNamespace,method));
//必须这样增加参数
call.addParameter(new QName(targetNamespace,"strUid"),XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName(targetNamespace,"strDateTime_start"),XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName(targetNamespace,"strDateTime_end"),XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName(targetNamespace,"strKPI_set"),XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName(targetNamespace,"nType"),XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName(targetNamespace,"strMem"),XMLType.XSD_STRING,ParameterMode.IN);
call.addParameter(new QName(targetNamespace,"strFilter"),XMLType.XSD_STRING,ParameterMode.IN);
//设置返回类型
call.setReturnType(XMLType.XSD_STRING);
call.setUseSOAPAction(true);
//可在wsdl:binding 中找到
call.setSOAPActionURI("http://tempuri.org/get_report_data");
call.setEncodingStyle("utf-8");
String result=(String)call.invoke(new Object[]{null,"2018-06-09","2018-06-12","1",68,null,null});
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
}