`
leon1509
  • 浏览: 527135 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JAVA使用axis调用WSDL的WebService

    博客分类:
  • JAVA
阅读更多
import javax.xml.rpc.ParameterMode;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

public class caClient {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			String endpoint = "http://ls.cqu.edu.cn/WebService/LibraryInterface.asmx?WSDL";
			// 直接引用远程的wsdl文件
			// 以下都是套路
			Service service = new Service();

			Call call = (Call) service.createCall();
			call.setTargetEndpointAddress(endpoint);
			call.setOperationName("SetLibraryValue");// WSDL里面描述的接口名称

			call.setSOAPActionURI("http://ls.cqu.edu.cn/SetLibraryValue");
			call.addParameter("Key", XMLType.XSD_STRING, ParameterMode.IN);// 接口的参数
			call.addParameter("XH", XMLType.XSD_STRING, ParameterMode.IN);// 接口的参数
			call.addParameter("HJDM", XMLType.XSD_STRING, ParameterMode.IN);// 接口的参数
			call.addParameter("BLSM", XMLType.XSD_STRING, ParameterMode.IN);// 接口的参数
			call.addParameter("SetState", XMLType.XSD_STRING, ParameterMode.IN);// 接口的参数
			call.addParameter("CZRID", XMLType.XSD_STRING, ParameterMode.IN);// 接口的参数
			call.addParameter("LogIP", XMLType.XSD_STRING, ParameterMode.IN);// 接口的参数

			call.setReturnType(XMLType.XSD_STRING);// 设置返回类型

			String key = "ewfasdfdsafew23434";
			String xh = "22";
			String hjdm = "33";
			String blsm = "33";
			String ss = "33";
			String cid = "33";
			String ip = "33";
			String result = (String) call.invoke(new Object[] { key, xh, hjdm, blsm, ss, cid, ip });

			// 给方法传递参数,并且调用方法
			System.out.println("result is " + result);
		} catch (Exception e) {
			System.err.println(e.toString());
		}
	}

}


上面的 WSDL 返回内容为:
  <?xml version="1.0" encoding="utf-8" ?> 
- <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://ls.cqu.edu.cn/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://ls.cqu.edu.cn/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://ls.cqu.edu.cn/">
- <s:element name="GetLibraryValue">
- <s:complexType>
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="Key" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="XH" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="HJDM" type="s:string" /> 
  </s:sequence>
  </s:complexType>
  </s:element>
- <s:element name="GetLibraryValueResponse">
- <s:complexType>
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="GetLibraryValueResult" type="s:string" /> 
  </s:sequence>
  </s:complexType>
  </s:element>
- <s:element name="SetLibraryValue">
- <s:complexType>
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="Key" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="XH" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="HJDM" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="BLSM" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="SetState" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="CZRID" type="s:string" /> 
  <s:element minOccurs="0" maxOccurs="1" name="LogIP" type="s:string" /> 
  </s:sequence>
  </s:complexType>
  </s:element>
- <s:element name="SetLibraryValueResponse">
- <s:complexType>
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="SetLibraryValueResult" type="s:string" /> 
  </s:sequence>
  </s:complexType>
  </s:element>
  </s:schema>
  </wsdl:types>
- <wsdl:message name="GetLibraryValueSoapIn">
  <wsdl:part name="parameters" element="tns:GetLibraryValue" /> 
  </wsdl:message>
- <wsdl:message name="GetLibraryValueSoapOut">
  <wsdl:part name="parameters" element="tns:GetLibraryValueResponse" /> 
  </wsdl:message>
- <wsdl:message name="SetLibraryValueSoapIn">
  <wsdl:part name="parameters" element="tns:SetLibraryValue" /> 
  </wsdl:message>
- <wsdl:message name="SetLibraryValueSoapOut">
  <wsdl:part name="parameters" element="tns:SetLibraryValueResponse" /> 
  </wsdl:message>
- <wsdl:portType name="LibraryInterfaceSoap">
- <wsdl:operation name="GetLibraryValue">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><B>获取学生某环节办理情况</B><p> <span style='color:green'><B>参数说明:</B></span> Key:钥匙 XH:学号 HJDM:环节代码 </BR><span style='color:red'><B>返回值说明:</B> 0:未通过办理 1:已通过办理 420:批次未启用 430:钥匙错误 440:学号不存在或者该学生未进入离校系统 450:环节代码错误</span><BR/></wsdl:documentation> 
  <wsdl:input message="tns:GetLibraryValueSoapIn" /> 
  <wsdl:output message="tns:GetLibraryValueSoapOut" /> 
  </wsdl:operation>
- <wsdl:operation name="SetLibraryValue">
  <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><B>设置学生某环节办理状态</B><p> <span style='color:green'><B>参数说明:</B></span> Key:钥匙 XH:学号 HJDM:环节代码 BLSM:办理说明 SetState:设置状态[1,0](分别为已通过和未通过) CZRID:办理人身份认证号 LogIP:办理人登陆IP</BR><span style='color:red'><B>返回值说明:</B> 200:设置成功 420:批次未启用 430:钥匙错误 440:学号不存在或者该学生未进入离校系统 450:环节代码错误 460:环节状态设置错误 470:写入日志出错</span><BR/><center>版权所有:Copyright 重庆大学 www.cqu.edu.cn</center></wsdl:documentation> 
  <wsdl:input message="tns:SetLibraryValueSoapIn" /> 
  <wsdl:output message="tns:SetLibraryValueSoapOut" /> 
  </wsdl:operation>
  </wsdl:portType>
- <wsdl:binding name="LibraryInterfaceSoap" type="tns:LibraryInterfaceSoap">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="GetLibraryValue">
  <soap:operation soapAction="http://ls.cqu.edu.cn/GetLibraryValue" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="SetLibraryValue">
  <soap:operation soapAction="http://ls.cqu.edu.cn/SetLibraryValue" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:binding name="LibraryInterfaceSoap12" type="tns:LibraryInterfaceSoap">
  <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="GetLibraryValue">
  <soap12:operation soapAction="http://ls.cqu.edu.cn/GetLibraryValue" style="document" /> 
- <wsdl:input>
  <soap12:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap12:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="SetLibraryValue">
  <soap12:operation soapAction="http://ls.cqu.edu.cn/SetLibraryValue" style="document" /> 
- <wsdl:input>
  <soap12:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap12:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:service name="LibraryInterface">
- <wsdl:port name="LibraryInterfaceSoap" binding="tns:LibraryInterfaceSoap">
  <soap:address location="http://ls.cqu.edu.cn/WebService/LibraryInterface.asmx" /> 
  </wsdl:port>
- <wsdl:port name="LibraryInterfaceSoap12" binding="tns:LibraryInterfaceSoap12">
  <soap12:address location="http://ls.cqu.edu.cn/WebService/LibraryInterface.asmx" /> 
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>
分享到:
评论
2 楼 leon1509 2011-10-18  
只要有数据返回,不管是啥格式,该咋处理咋处理!XML就用dom4j或sax或jdom处理呗!
1 楼 zq_zero 2011-10-17  
如果接口方返回的是xml,该怎么处理啊?

相关推荐

Global site tag (gtag.js) - Google Analytics