糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > Java调用soap协议的webservice

Java调用soap协议的webservice

时间:2024-03-20 07:51:59

相关推荐

Java调用soap协议的webservice

Java调用soap协议的webservice

package test;import org.apache.axis.utils.StringUtils;import org.apache.axis.client.Call;import org.apache.axis.client.Service;public class CalculateClient {public static void main(String[] args) {// 指定调用WebService的URL(这里是我们发布后点击HelloWorld)String url = "http://localhost:8080/services/HelloWorld?wsdl";//调用的方法String method = "add";//调用方法的参数列表Object[] parms = new Object[]{2.0,3.0};CalculateClient calculateClient = new CalculateClient();//调用方法String svrAddResult = calculateClient.CallMethod(url, method, parms);System.out.println(svrAddResult);String svrMinusResult = calculateClient.CallMethod(url, "minus", new Object[]{5.0,2.0});String svrMultiplyResult = calculateClient.CallMethod(url, "multiply", new Object[]{2.0,3.0});String svrDivideResult = calculateClient.CallMethod(url, "divide", new Object[]{8.0,5.0});String svrPowerResult = calculateClient.CallMethod(url, "power", new Object[]{5.0});String svrSqrtResult = calculateClient.CallMethod(url, "sqrt", new Object[]{9.0});System.out.println("5.0 - 2.0 is " + svrMinusResult);System.out.println("2.0 * 3.0 is " + svrMultiplyResult);System.out.println("8.0 - 5.0 is " + svrDivideResult);System.out.println("5.0^2 is " + svrPowerResult);System.out.println("9.0^(1/2) is " + svrSqrtResult);}//实现WebService上发布的服务调用public String CallMethod(String url, String method, Object[] args) {String result = null;if(StringUtils.isEmpty(url)) {return "url地址为空";}if(StringUtils.isEmpty(method)) {return "method地址为空";}Call rpcCall = null;try {//实例websevice调用实例Service webService = new Service();rpcCall = (Call) webService.createCall();rpcCall.setTargetEndpointAddress(new .URL(url));rpcCall.setOperationName(method);//执行webservice方法double rslt = (double) rpcCall.invoke(args);result = String.valueOf(rslt);} catch (Exception e) {e.printStackTrace();}return result;}}

https://amr./szjxjgw/services/Spemainser?wsdl

package com.czh;import org.apache.axis.utils.StringUtils;import org.apache.axis.client.Call;import org.apache.axis.client.Service;/*** 调用服务的客户端*/public class CalculateClient {public static void main(String[] args) {// 指定调用WebService的URL(这里是我们发布后点击HelloWorld)String url = "https://amr./szjxjgw/services/Spemainser?wsdl";//调用的方法String method = "changemainten";//调用方法的参数列表Object[] parms = new Object[]{"{'contenttype':'4','userinfo':{'userid':'AA12','timestamp':'-12-22 15:34:43','nonce':'abcdef','signature':'4330e2dcf44f131f258527ef002f5d0a85423f6c'},'content':{'maintnote':{'normalmainttime':'-06-10','mainttype':'1','mainttime':'-10-26 15:34:43','maintstaff':'1','maintstafftel':'1','notifytime':'-10-26 15:34:43','arrivetime':'-10-26 15:34:43','endtime':'-10-26 15:34:43','servicetype':'1','otherservice':'1','faultdesc':'1','resolveresult':'1','partscode':'1','deliverynum':'1','remark':'1','useorgopinion':'1','maintstaffid':'1','useorgstaff':'1','useorgname':'1','maintorgname':'1','status':'1','createdtime':'-06-10','ismakeup':'1','elevcode':'1','elevtype':'1','makeuptime':'-06-10','useorgcontime':'-06-10','useorgstaffid':'4545','maintorgcode':'444','useorgmanager':'444','useorgpone':'444','elevlongit':'444','elevlatit':'444'},'halfmonthmaintitem':{'hm1':'2','hm2':'2','hm3':'2','hm4':'2','hm5':'2','hm6':'2','hm7':'2','hm8':'2','hm9':'2','hm10':'2','hm11':'2','hm12':'2','hm13':'2','hm14':'2','hm15':'2','hm16':'2','hm17':'2'},'quartermaintitem':{'qtr1':'3','qtr2':'3','qtr3':'3','qtr4':'3','qtr5':'3','qtr6':'3','qtr7':'3','qtr8':'3','qtr9':'3','qtr10':'3'},'halfyearmaintitem':{'hy1':'4','hy2':'4','hy3':'4','hy4':'4','hy5':'4','hy6':'4','hy7':'4','hy8':'4','hy9':'4','hy10':'4'},'yearmaintitem':{'y1':'5','y2':'5','y3':'5','y4':'5','y5':'5','y6':'5','y7':'5','y8':'5','y9':'5','y10':'5','y11':'5','y12':'5','y13':'5','y14':'5'}}}"};CalculateClient calculateClient = new CalculateClient();//调用方法String svrAddResult = calculateClient.CallMethod(url, method, parms);System.out.println(svrAddResult);}//实现WebService上发布的服务调用public String CallMethod(String url, String method, Object[] args) {String result = null;if(StringUtils.isEmpty(url)) {return "url地址为空";}if(StringUtils.isEmpty(method)) {return "method地址为空";}Call rpcCall = null;try {//实例websevice调用实例Service webService = new Service();rpcCall = (Call) webService.createCall();rpcCall.setTargetEndpointAddress(new .URL(url));rpcCall.setOperationName(method);//执行webservice方法String rslt = (String)rpcCall.invoke(args);result = String.valueOf(rslt);} catch (Exception e) {e.printStackTrace();}return result;}}

<?xml version="1.0" encoding="UTF-8"?><project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.czh</groupId><artifactId>webserviceCall</artifactId><version>1.0-SNAPSHOT</version><name>webserviceCall</name><!-- FIXME change it to the project's website --><url></url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><piler.source>1.7</piler.source><piler.target>1.7</piler.target></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><dependency><groupId>org.codehaus.xfire</groupId><artifactId>xfire-aegis</artifactId><version>1.2.6</version></dependency><dependency><groupId>org.codehaus.xfire</groupId><artifactId>xfire-all</artifactId><version>1.2.6</version><exclusions><exclusion><groupId>org.codehaus.xfire</groupId><artifactId>xfire-spring</artifactId></exclusion></exclusions></dependency><!-- /artifact/javax.servlet/javax.servlet-api --><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>4.0.1</version><scope>provided</scope></dependency><!-- /artifact/javax.xml.rpc/javax.xml.rpc-api --><dependency><groupId>javax.xml.rpc</groupId><artifactId>javax.xml.rpc-api</artifactId><version>1.1</version></dependency><dependency><groupId>org.apache.axis</groupId><artifactId>axis</artifactId><version>1.4</version></dependency></dependencies><build><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><plugin><artifactId>maven-clean-plugin</artifactId><version>3.0.0</version></plugin><!-- see /ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --><plugin><artifactId>maven-resources-plugin</artifactId><version>3.0.2</version></plugin><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.7.0</version></plugin><plugin><artifactId>maven-surefire-plugin</artifactId><version>2.20.1</version></plugin><plugin><artifactId>maven-jar-plugin</artifactId><version>3.0.2</version></plugin><plugin><artifactId>maven-install-plugin</artifactId><version>2.5.2</version></plugin><plugin><artifactId>maven-deploy-plugin</artifactId><version>2.8.2</version></plugin></plugins></pluginManagement></build></project>

找不到引入的时候来这里查/

如果觉得《Java调用soap协议的webservice》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。