Java_Webservice调用方式详解.doc_第1页
Java_Webservice调用方式详解.doc_第2页
Java_Webservice调用方式详解.doc_第3页
Java_Webservice调用方式详解.doc_第4页
Java_Webservice调用方式详解.doc_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Java - Webservice调用方式详解调用webservice,可以首先根据wsdl文件生成客户端,或者直接根据地址调用,下面讨论直接调用地址的两种不同方式:axis和Soap,soap方式主要是用在websphere下axis方式调用:import java.util.Date;import java.text.DateFormat;import org.apache.axis.client.Call;import org.apache.axis.client.Service;import space.QName;import java.lang.Integer;import javax.xml.rpc.ParameterMode;public class caClient public static void main(String args) try String endpoint = http:/localhost:8080/ca3/services/caSynrochnized?wsdl;Service service = new Service();Call call = (Call) service.createCall();call.setTargetEndpointAddress(endpoint);call.setOperationName(addUser);call.addParameter(userName, org.apache.axis.encoding.XMLType.XSD_DATE,javax.xml.rpc.ParameterMode.IN);call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);call.setUseSOAPAction(true);call.setSOAPActionURI(/Rpc);/Integer k = (Integer) call.invoke(new Object i, j );/System.out.println(result is + k.toString() + .);String temp = 测试人员;String result = (String)call.invoke(new Objecttemp);System.out.println(result is +result);catch (Exception e) System.err.println(e.toString();soap方式调用import org.apache.soap.util.xml.*;import org.apache.soap.*;import org.apache.soap.rpc.*;import java.io.*;import .*;import java.util.Vector;public class caServicepublic static String getService(String user) URL url = null;try url=new URL(00:8080/ca3/services/caSynrochnized); catch (MalformedURLException mue) return mue.getMessage();/ This is the main SOAP objectCall soapCall = new Call();/ Use SOAP encodingsoapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);/ This is the remote object were asking for the pricesoapCall.setTargetObjectURI(urn:xmethods-caSynrochnized);/ This is the name of the method on the above objectsoapCall.setMethodName(getUser);/ We need to send the ISBN number as an input parameter to the methodVector soapParams = new Vector();/ name, type, value, encoding styleParameter isbnParam = new Parameter(userName, String.class, user, null);soapParams.addElement(isbnParam);soapCall.setParams(soapParams);try / Invoke the remote method on the objectResponse soapResponse = soapCall.invoke(url,);/ Check to see if there is an error, return N/Aif (soapResponse.generatedFault() Fault fault = soapResponse.getFault();String f = fault.getFaultString();return f; else / read resultParameter soapResult = soapResponse.getReturnValue ();/ get a string from the resultreturn soapResult.getValue().toString(); catch (SOAPException se) return se.getMessage();返回一维数组时Parameter soapResult = soapResponse.getReturnValue();String temp = (String)soapResult.getValue();调用ASP.Net生成的webserviceprivate String HelloWorld(String uri, String u) try SOAPMappingRegistry smr = new SOAPMappingRegistry();StringDeserializer sd = new StringDeserializer();ArraySerializer arraySer = new ArraySerializer();BeanSerializer beanSer = new BeanSerializer();smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName(/, HelloWorldResult), String.class,null, sd);smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName(/, temp), String.class,beanSer, beanSer);URL url = new URL(uri);Call call = new Call();call.setSOAPMappingRegistry(smr);call.setTargetObjectURI(urn:xmethods-Service1);call.setMethodName(HelloWorld);call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);Vector soapParams = new Vector();soapParams.addElement(new Parameter(temp, String.class, u, null);call.setParams(soapParams);Response soapResponse = call.invoke(url,/HelloWorld);if (soapResponse.generatedFault() Fault fault = soapResponse.getFault();System.out.p

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论