加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

客户端调用Webservice例子(Axis)

发布时间:2020-12-17 02:32:27 所属栏目:安全 来源:网络整理
导读:import org.apache.axis.client.Call; import org.apache.axis.client.Service; public class CallWebServiceClient { ? ?/** ? * @param args ? * @throws Exception ? */ ?public static void main(String[] args)? { ?? try { ??? ?String endpoint = "ht

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;


public class CallWebServiceClient {
?
?/**
? * @param args
? * @throws Exception
? */
?public static void main(String[] args)? {
?? try {
??? ?String endpoint = "http://172.25.165.45:8080/spc/services/spcRealTimeMonitorService ";
????????? Service service = new Service();
????????? Call call = null;
????????? call = (Call) service.createCall();
????????? call.setTargetEndpointAddress(new java.net.URL(endpoint));
????????? call.setOperationName("spcDownload");??
????????? call.setReturnType(call.getReturnType());??
????????? call.invoke( new Object[]{});
?????????? } catch (Exception e) {
???????? ?? System.out.println(e);
?????????? } finally {
????????? }
?}
}

?

//

<? xml version="1.0" encoding="UTF-8" ?>

- < wsdl:definitions targetNamespace =" http://172.25.165.45:8080/spc/services/spcRealTimeMonitorService " xmlns:apachesoap =" http://xml.apache.org/xml-soap " xmlns:impl =" http://172.25.165.45:8080/spc/services/spcRealTimeMonitorService " xmlns:intf =" http://172.25.165.45:8080/spc/services/spcRealTimeMonitorService " xmlns:soapenc =" http://schemas.xmlsoap.org/soap/encoding/ " xmlns:wsdl =" http://schemas.xmlsoap.org/wsdl/ " xmlns:wsdlsoap =" http://schemas.xmlsoap.org/wsdl/soap/ " xmlns:xsd =" http://www.w3.org/2001/XMLSchema " >
- <!--
WSDL created by Apache Axis version: 1.4

Built on Apr 22,2006 (06:55:48 PDT)

? -->
- < wsdl:message name =" getStatusResponse " >
? < wsdl:part name =" getStatusReturn " type =" xsd:string " />
? </ wsdl:message >
- < wsdl:message name =" getStatusRequest " >
? < wsdl:part name =" id " type =" xsd:int " />
? < wsdl:part name =" groupType " type =" xsd:int " />
? </ wsdl:message >
- < wsdl:message name =" spcDownloadResponse " >
? < wsdl:part name =" spcDownloadReturn " type =" xsd:string " />
? </ wsdl:message >
- < wsdl:message name =" operateMonitorBTRequest " >
? < wsdl:part name =" id " type =" xsd:int " />
? < wsdl:part name =" status " type =" xsd:string " />
? < wsdl:part name =" operate " type =" xsd:string " />
? </ wsdl:message >
? < wsdl:message name =" operateMonitorBBResponse " />
? < wsdl:message name =" spcDownloadRequest " />
- < wsdl:message name =" operateMonitorBBRequest " >
? < wsdl:part name =" id " type =" xsd:int " />
? < wsdl:part name =" status " type =" xsd:string " />
? < wsdl:part name =" operate " type =" xsd:string " />
? </ wsdl:message >
? < wsdl:message name =" operateMonitorBTResponse " />
- < wsdl:portType name =" JaxRpcSpcRealTimeMonitorService " >
- < wsdl:operation name =" operateMonitorBT " parameterOrder =" id status operate " >
? < wsdl:input message =" impl:operateMonitorBTRequest " name =" operateMonitorBTRequest " />
? < wsdl:output message =" impl:operateMonitorBTResponse " name =" operateMonitorBTResponse " />
? </ wsdl:operation >
- < wsdl:operation name =" operateMonitorBB " parameterOrder =" id status operate " >
? < wsdl:input message =" impl:operateMonitorBBRequest " name =" operateMonitorBBRequest " />
? < wsdl:output message =" impl:operateMonitorBBResponse " name =" operateMonitorBBResponse " />
? </ wsdl:operation >
- < wsdl:operation name =" spcDownload " >
? < wsdl:input message =" impl:spcDownloadRequest " name =" spcDownloadRequest " />
? < wsdl:output message =" impl:spcDownloadResponse " name =" spcDownloadResponse " />
? </ wsdl:operation >
- < wsdl:operation name =" getStatus " parameterOrder =" id groupType " >
? < wsdl:input message =" impl:getStatusRequest " name =" getStatusRequest " />
? < wsdl:output message =" impl:getStatusResponse " name =" getStatusResponse " />
? </ wsdl:operation >
? </ wsdl:portType >
- < wsdl:binding name =" spcRealTimeMonitorServiceSoapBinding " type =" impl:JaxRpcSpcRealTimeMonitorService " >
? < wsdlsoap:binding style =" rpc " transport =" http://schemas.xmlsoap.org/soap/http " />
- < wsdl:operation name =" operateMonitorBT " >
? < wsdlsoap:operation soapAction =" " />
- < wsdl:input name =" operateMonitorBTRequest " >
? < wsdlsoap:body encodingStyle =" http://schemas.xmlsoap.org/soap/encoding/ " namespace =" http://webservice.remote.server.spc.scion.sanminasci.com " use =" encoded " />
? </ wsdl:input >
- < wsdl:output name =" operateMonitorBTResponse " >
? < wsdlsoap:body encodingStyle =" http://schemas.xmlsoap.org/soap/encoding/ " namespace =" http://172.25.165.45:8080/spc/services/spcRealTimeMonitorService " use =" encoded " />
? </ wsdl:output >
? </ wsdl:operation >
- < wsdl:operation name =" operateMonitorBB " >
? < wsdlsoap:operation soapAction =" " />
- < wsdl:input name =" operateMonitorBBRequest " >
? < wsdlsoap:body encodingStyle =" http://schemas.xmlsoap.org/soap/encoding/ " namespace =" http://webservice.remote.server.spc.scion.sanminasci.com " use =" encoded " />
? </ wsdl:input >
- < wsdl:output name =" operateMonitorBBResponse " >
? < wsdlsoap:body encodingStyle =" http://schemas.xmlsoap.org/soap/encoding/ " namespace =" http://172.25.165.45:8080/spc/services/spcRealTimeMonitorService " use =" encoded " />
? </ wsdl:output >
? </ wsdl:operation >
- < wsdl:operation name =" spcDownload " >
? < wsdlsoap:operation soapAction =" " />
- < wsdl:input name =" spcDownloadRequest " >
? < wsdlsoap:body encodingStyle =" http://schemas.xmlsoap.org/soap/encoding/ " namespace =" http://webservice.remote.server.spc.scion.sanminasci.com " use =" encoded " />
? </ wsdl:input >
- < wsdl:output name =" spcDownloadResponse " >
? < wsdlsoap:body encodingStyle =" http://schemas.xmlsoap.org/soap/encoding/ " namespace =" http://172.25.165.45:8080/spc/services/spcRealTimeMonitorService " use =" encoded " />
? </ wsdl:output >
? </ wsdl:operation >
- < wsdl:operation name =" getStatus " >
? < wsdlsoap:operation soapAction =" " />
- < wsdl:input name =" getStatusRequest " >
? < wsdlsoap:body encodingStyle =" http://schemas.xmlsoap.org/soap/encoding/ " namespace =" http://webservice.remote.server.spc.scion.sanminasci.com " use =" encoded " />
? </ wsdl:input >
- < wsdl:output name =" getStatusResponse " >
? < wsdlsoap:body encodingStyle =" http://schemas.xmlsoap.org/soap/encoding/ " namespace =" http://172.25.165.45:8080/spc/services/spcRealTimeMonitorService " use =" encoded " />
? </ wsdl:output >
? </ wsdl:operation >
? </ wsdl:binding >
- < wsdl:service name =" JaxRpcSpcRealTimeMonitorServiceService " >
- < wsdl:port binding =" impl:spcRealTimeMonitorServiceSoapBinding " name =" spcRealTimeMonitorService " >
? < wsdlsoap:address location =" http://172.25.165.45:8080/spc/services/spcRealTimeMonitorService " />
? </ wsdl:port >
? </ wsdl:service >
? </ wsdl:definitions >





=========================================
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;

import com.mycompany.MonitoredObjectTo;


??? String ip="localhost";
??? ??? try{
??? ??? ??? String endpoint = "http://"+ip+":8080/test/services/spcMonitoredObjectService";
??? ??? ??? System.out.println( endpoint? );
??? ??????? Service? service = new Service();
??? ??????? Call???? call??? = (Call) service.createCall();
??? ??????? call.setTargetEndpointAddress( new java.net.URL(endpoint) );
??? ??????? call.setOperationName("getAllSpcMonitoredObject");
??? ??? ??? QName qn = new QName("urn:myUrn","MonitoredObjectTo");
??? ??? ??? call.registerTypeMapping(MonitoredObjectTo.class,qn,new BeanSerializerFactory(MonitoredObjectTo.class,qn),new BeanDeserializerFactory(MonitoredObjectTo.class,qn));
??? ?????? /
??? ??????? Object[] object=(Object[])? call.invoke( new Object[] {} );
??? ??? ??? if (object !=null){
??? ??? ??? ??? for(int i=0;i<object.length;i++){
??? ??? ??? ??? ??? MonitoredObjectTo monitoredObject= (MonitoredObjectTo) object[i];
??? ??? ??? ??? ??? System.out.println( monitoredObject.getObjectName() );
??? ??? ??? ??? }
??? ??? ??? }
??? ??? }catch(Exception e){
??? ??? ??? e.printStackTrace();
??? ??? }finally{
??? ??? ???
??? ??? }

带参数例子

??? ??? String endpoint = "http://172.25.165.1:8080/xxx/services/serverInfo";
??? ??? Service service = new Service();
??? ??? Call call = null;
??? ??? call = (Call) service.createCall();
??? ??? QName qn = new QName("urn:xxxx","MachineMap");
??? ??? call.setTargetEndpointAddress(new java.net.URL(endpoint));
??? ??? call.registerTypeMapping(MachineMap.class,new BeanSerializerFactory(MachineMap.class,new BeanDeserializerFactory(MachineMap.class,qn));
??? ??? call.setOperationName(new QName(endpoint,"getMachineByProgramName"));
??? ??? call.setReturnType(call.getReturnType());??
??? ??? System.out.println( ((Object[])call.invoke(new Object[] {" XXX "})).length); //XXX为输入参数

另外
浏览器如何罗列webservice 数据 ,参考格式
http://yourmachine:port/webapplication/services/yourWebservice?method=methodName
http://172.25.165.9:8080/myApplication/services/EmailService?method=getAllEmail
带参数的URL查询
http://172.25.165.1:8080/XXXX/services/serverInfo?method=getMachineByProgramName&programName=XXX

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读