JAVA 读取webservice接口
来源:互联网 发布:ubuntu 镜像 知乎 编辑:程序博客网 时间:2024/05/16 04:55
1. wsdl
<?xml version="1.0" encoding="utf-8" ?>
<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:import namespace="http://www.w3.org/2001/XMLSchema" />
<s:element name="GetIdPerinfo">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="in_id" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetIdPerinfoResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetIdPerinfoResult">
<s:complexType>
<s:sequence>
<s:element ref="s:schema" />
<s:any />
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="GetIdPerinfoSoapIn">
<wsdl:part name="parameters" element="tns:GetIdPerinfo" />
</wsdl:message>
<wsdl:message name="GetIdPerinfoSoapOut">
<wsdl:part name="parameters" element="tns:GetIdPerinfoResponse" />
</wsdl:message>
<wsdl:portType name="HRODBShareSoap">
<wsdl:operation name="GetIdPerinfo">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/">按指定的ID得到基本信息</documentation>
<wsdl:input message="tns:GetIdPerinfoSoapIn" />
<wsdl:output message="tns:GetIdPerinfoSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HRODBShareSoap" type="tns:HRODBShareSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<wsdl:operation name="GetIdPerinfo">
<soap:operation soapAction="http://tempuri.org/GetIdPerinfo" 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="HRODBShare">
</wsdl:definitions>
2. Java 代码
package mytest;
import java.io.ByteArrayInputStream;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.types.Schema;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
public class CallWS {
public String invoke(Object [] obj ) throws Exception
{
String endpointURL = "http://10.3.6.53/hroweb/hrodbshare.asmx";
String namespaceURI = "http://tempuri.org/" ;//命名空间
String soapactionURI = "http://tempuri.org/GetIdPerinfo"; //soapactionURI
String remotemethod = "GetIdPerinfo";//方法名
String id="147493";
Service service = new Service();
Call call=(Call) service.createCall();
call.addParameter(new QName(namespaceURI,"in_id"),org.apache.axis.encoding.XMLType.XSD_STRING ,javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_SCHEMA);
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapactionURI);
call.setTargetEndpointAddress(new java.net.URL(endpointURL).toString() );
QName qname = new QName(namespaceURI, remotemethod);
call.setOperationName(qname);
Schema schema = (Schema) call.invoke(obj);
String res = schema.get_any()[1].getAsString();
return res;
}
public static void main(String [] args) throws Exception
{
CallWS ll = new CallWS();
try
{
String s = ll.invoke(new Object[]{"147493"});
SAXReader reader = new SAXReader();
Document doc = reader.read(new ByteArrayInputStream(s.getBytes()));
Node node = (Node) doc.selectSingleNode("/diffgr:diffgram/NewDataSet/Table/NOTES_EMAIL");
System.out.println("getStringValue(): "+node.getStringValue());//
System.out.println("getText(): "+node.getText());//node.getStringValue() = node.getText()
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RemoteException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ServiceException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
- JAVA 读取webservice接口
- JAVA 读取webservice接口
- java访问WebService接口
- Java WebService 接口调用
- java调用webservice 接口
- java调用webservice接口
- Java调用WebService接口
- java 调用webservice接口
- java webservice接口开发
- JAVA WebService接口调用
- java调用webservice接口
- java 调用webservice接口
- Java调用webservice接口
- java 调用webservice接口
- Java调用webService接口
- java请求webservice接口
- java调用webService接口
- java调用WebService接口
- 关闭WordPress的主题、插件、版本更新通知
- sql server - varchar(max), NVARCHAR(MAX), VARBINARY(MAX) (zz)
- java 多线程经典例子——生产者与消费者的问题
- ffmep教程二 —— ffmpeg环境搭建
- Ecplise juno版本安装Maven-SVN插件方式
- JAVA 读取webservice接口
- 上交所、深交所配股的资金交收与股份交收流程
- ZOJ 2859 Matrix Searching
- Windows2003 Enterprise Edition 服务里没有NT LM Security Support Provider
- sql server 的规格参数,限制等 (zz)
- dip, dp, px, sp区别
- AltiumDesigner中从PCB文件更新SCH文件元件标号--PCB自动标号
- /etc/default/grub文件
- C# Windows 服务 的简单程序的编写,安装 和 卸载