資源描述:
《java_webservice調(diào)用方式詳解》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、Java-Webservice調(diào)用方式詳解調(diào)用webservice,可以首先根據(jù)wsdl文件生成客戶端,或者直接根據(jù)地址調(diào)用,下面討論直接調(diào)用地址的兩種不同方式:axis和Soap,soap方式主要是用在websphere下axis方式調(diào)用:importjava.util.Date;importjava.text.DateFormat;importorg.apache.axis.client.Call;importorg.apache.axis.client.Service;importjavax.xml.namespace.QName;importjava.lang.
2、Integer;importjavax.xml.rpc.ParameterMode;publicclasscaClient{publicstaticvoidmain(String[]args){try{Stringendpoint="http://localhost:8080/ca3/services/caSynrochnized?wsdl";Serviceservice=newService();Callcall=(Call)service.createCall();call.setTargetEndpointAddress(endpoint);call.setOpe
3、rationName("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("http://www.my.com/Rpc");//Integerk=(Integer)call
4、.invoke(newObject[]{i,j});//System.out.println("resultis"+k.toString()+".");Stringtemp="測(cè)試人員";Stringresult=(String)call.invoke(newObject[]{temp});System.out.println("resultis"+result);}catch(Exceptione){System.err.println(e.toString());}}}soap方式調(diào)用importorg.apache.soap.util.xml.*;importor
5、g.apache.soap.*;importorg.apache.soap.rpc.*;importjava.io.*;importjava.net.*;importjava.util.Vector;publicclasscaService{publicstaticStringgetService(Stringuser){URLurl=null;try{url=newURL("http://192.168.0.100:8080/ca3/services/caSynrochnized");}catch(MalformedURLExceptionmue){returnmue
6、.getMessage();}//ThisisthemainSOAPobjectCallsoapCall=newCall();//UseSOAPencodingsoapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);//Thisistheremoteobjectwe'reaskingforthepricesoapCall.setTargetObjectURI("urn:xmethods-caSynrochnized");//ThisisthenameofthemethodontheaboveobjectsoapCa
7、ll.setMethodName("getUser");//WeneedtosendtheISBNnumberasaninputparametertothemethodVectorsoapParams=newVector();//name,type,value,encodingstyleParameterisbnParam=newParameter("userName",String.class,user,null);soapParams.addElement(isbnParam);soapCall.setParams(soapParam