微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

客户端调用Webservice例子(Axis)

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐