webservice客户端开发
生活随笔
收集整理的這篇文章主要介紹了
webservice客户端开发
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、根據約定條件生成客戶端
1.需要axis.jar包
2.調用
import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; public static void main(String[] args)(String param1, Date param2, double param3) {String url = "http:IP:PORT/url" ;try {Service service = new Service();Call call = (Call) service.createCall();//調用的url地址 call.setTargetEndpointAddress(url);//調用的方法名call.setOperationName( "doService" );//參數,有幾個寫幾個,類型對應call.addParameter( "parameter1" ,org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN ) ;call.addParameter( "parameter2" ,org.apache.axis.encoding.XMLType.XSD_DATE,javax.xml.rpc.ParameterMode.IN ) ;call.addParameter( "parameter3" ,org.apache.axis.encoding.XMLType.XSD_DOUBLE,javax.xml.rpc.ParameterMode.IN ) ;//返回值類型call.setReturnType(XMLType.XSD_STRING );
call.setUseSOAPAction( true );
//對應的參數String result = (String) call.invoke( new Object[]{param1,param2,param3}) ; } catch (javax.xml.rpc.ServiceException e) {e.printStackTrace();} catch (RemoteException e) {e.printStackTrace();} }
?
二、根據wsdl文件生成客戶端
1.新建webservice客戶端 2.選擇wsdl文件、client level、運行時環境,環境用tomcat 3.選擇生成的目錄 4.啟動tomcat 5.確定生成的方法 6.生成代碼 7.調用 public static void main(String[] args) {//訪問webservice的地址String url = "http://IP:PORT/url" ;try {XXXBindingStub binding;binding = (XXXBindingStub)new XXXLocator().getXXXHttpSoap11Endpoint(new java.net.URL(url));//參數String result = binding.send( "param", "param", "param");//結果 System. out.println(result);} catch (MalformedURLException e) {e.printStackTrace();} catch (ServiceException e) {e.printStackTrace();} catch (RemoteException e) {e.printStackTrace();} }?
轉載于:https://www.cnblogs.com/zcrutherford/p/5163875.html
總結
以上是生活随笔為你收集整理的webservice客户端开发的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: scp远程复制
- 下一篇: 如何用Windows Live Writ