使用axis自动生成webservice客户端代码

上传人:d**** 文档编号:159059499 上传时间:2022-10-08 格式:DOCX 页数:10 大小:20.61KB
返回 下载 相关 举报
使用axis自动生成webservice客户端代码_第1页
第1页 / 共10页
使用axis自动生成webservice客户端代码_第2页
第2页 / 共10页
使用axis自动生成webservice客户端代码_第3页
第3页 / 共10页
点击查看更多>>
资源描述
利用AXIS生成客户端文件,使得开发webservice更加简单,以下是我的个人代码, 工具:/、Myeclipse7.0, axis1.4, tomcat5.5, jdk1.5下载axis的jar包,我的是axis-bin-1_4.zip包,解压后有axis的lib目录,一会儿我们要用,在 myeclip se 中创建自己的 webservice 工程,这个在的文库里有,在C盘目录下创建一个批处理文件,我的名字是wsdltojava.bat,内容如下:set Axis_Lib=E:jaraxisasixToolaxis-bin-1_4axis-1_4libset Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%set Axis_Servlet=http:/localhost:8090/myAxis/services/HelloWorld?wsdl %Java_Cmd% org.apache.axis.wsdl.WSDL2Java -u %Axis_Servlet% 备注:红色字体我的axis的目录,也就是刚才我解压出来的axis,蓝色是我的 webservice 的访问地址,其他的不用处理, 然后双击这个文件,产生以下几个文件:(1) 、目录是: C:localhostmyAxisservicesHelloWorld(2) 、目jrlJServici. j na凰 Hdl 曲 prldS ervi c eLo c ator, j ava 目 He匚卅)r 115 o apBi ci tub. / av i1 3 :AVa丈件 1邓JAVa丈伴 t JAVA艾伴 r迤;ava 土伴2012-9-4 20:392012-9-4 20:39 迎汁4 EQ;39 2012-9-aruiL ar ask igthroirs S e rviceE x c e pt io n* Sthrmr s P.eeio teEz c e p t i口Jipulilxc 5ta.tic void lYiain (St-r iacj args) therms SeirviceEKcept- ioa.r ReizioteE:cceptian ( H已丄丄oworldServiceLonzator ukis = new HellovorLOervLceLocatDr (:iHelloiJor 1 cl hw 二 hum. gatHEllaUorld ();StrLnu ss 二 hmhellDH (J ;运行即可附录代码:服务端HelloWorld.javapackage webservice.axis.test;public class HelloWorld public String hello()return Hello +aaaaaaaaaaaaaaaaaa; 客户端(通过刚才命令生成的四个文件)HelloWorld.java/* HelloWorld.java* This file was auto-generated from WSDL* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */package webservice.axis.test.batClient;public interface HelloWorld extends java.rmi.Remote public java.lang.String hello() throws java.rmi.RemoteException;HelloWorldService.java/* HelloWorldService.java* This file was auto-generated from WSDL* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */package webservice.axis.test.batClient;public interface HelloWorldService extends javax.xml.rpc.Service public java.lang.String getHelloWorldAddress();publicwebservice.axis.test.batClient.HelloWorldgetHelloWorld()throwsjavax.xml.rpc.ServiceException;public webservice.axis.test.batClient.HelloWorld getHelloWorld(.URL portAddress) throws javax.xml.rpc.ServiceException;HelloWorldServiceLocator.java/* HelloWorldServiceLocator.java* This file was auto-generated from WSDL* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter. */package webservice.axis.test.batClient;public class HelloWorldServiceLocator extends org.apache.axis.client.Service implements webservice.axis.test.batClient.HelloWorldService public HelloWorldServiceLocator() public HelloWorldServiceLocator(org.apache.axis.EngineConfiguration config) super(config);public HelloWorldServiceLocator(java.lang.String wsdlLoc, javax.xml.namespace.QName sName) throws javax.xml.rpc.ServiceException super(wsdlLoc, sName);/ Use to get a proxy class for HelloWorldprivate java.lang.String HelloWorld_address = http:/localhost:8090/myAxis/services/HelloWorld;public java.lang.String getHelloWorldAddress() return HelloWorld_address;/ The WSDD service name defaults to the port name.public java.lang.String getHelloWorldWSDDServiceName() return HelloWorldWSDDServiceName;public void setHelloWorldWSDDServiceName(java.lang.String name) HelloWorldWSDDServiceName = name;public webservice.axis.test.batClient.HelloWorld getHelloWorld() throws javax.xml.rpc.ServiceException .URL endpoint;try endpoint = new .URL(HelloWorld_address);catch (.MalformedURLException e) throw new javax.xml.rpc.ServiceException(e);return getHelloWorld(endpoint);public webservice.axis.test.batClient.HelloWorld getHelloWorld(.URL portAddress) throws javax.xml.rpc.ServiceException try webservice.axis.test.batClient.HelloWorldSoapBindingStub _stub = new webservice.axis.test.batClient.HelloWorldSoapBindingStub(portAddress, this);_stub.setPortName(getHelloWorldWSDDServiceName(); return _stub;catch (org.apache.axis.AxisFault e) return null;public void setHelloWorldEndpointAddress(java.lang.String address) HelloWorld_address = address;/* For the given interface, get the stub implementation.* If this service has no port for the given interface,* then ServiceException is thrown.*/public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException try if (webservice.axis.test.batClient.HelloWorld.class.isAssignableFrom(serviceEndpointInterface) webservice.axis.test.batClient.HelloWorldSoapBindingStub _stub = new webservice.axis.test.batClient.HelloWorldSoapBindingStub(new .URL(HelloWorld_address), this);_stub.setPortName(getHelloWorldWSDDServiceName();return _stub;catch (java.lang.Throwable t) throw new javax.xml.rpc.ServiceException(t);throw new javax.xml.rpc.ServiceException(There is no stub implementation for the interface: + (serviceEndpointInterface = null ? null : serviceEndpointInterface.getName();/* For the given interface, get the stub implementation.* If this service has no port for the given interface,* then ServiceException is thrown.*/public java.rmi.Remote getPort(javax.xml.namespace.QName portName, Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException if (portName = null) return getPort(serviceEndpointInterface);java.lang.String inputPortName = portName.getLocalPart();if (HelloWorld.equals(inputPortName) return getHelloWorld();else java.rmi.Remote _stub = getPort(serviceEndpointInterface); (org.apache.axis.client.Stub) _stub).setPortName(portName); return _stub;public javax.xml.namespace.QName getServiceName() return newjavax.xml.namespace.QName(http:/localhost:8090/myAxis/services/HelloWorld, HelloWorldService);private java.util.HashSet ports = null;public java.util.Iterator getPorts() if (ports = null) ports = new java.util.HashSet();ports.add(newjavax.xml.namespace.QName(http:/localhost:8090/myAxis/services/HelloWorld, HelloWorld);return ports.iterator();* Set the endpoint address for the specified port name.*/public void setEndpointAddress(java.lang.String portName, java.lang.String address) throws javax.xml.rpc.ServiceException if (HelloWorld.equals(portName) setHelloWorldEndpointAddress(address);else / Unknown Port Namethrow new javax.xml.rpc.ServiceException( Cannot set Endpoint Address for Unknown Port + portName);/* Set the endpoint address for the specified port name.*/public void setEndpointAddress(javax.xml.namespace.QName portName, java.lang.String address) throws javax.xml.rpc.ServiceException setEndpointAddress(portName.getLocalPart(), address);HelloWorldSoapBindingStub.java* HelloWorldSoapBindingStub.java* This file was auto-generated from WSDL* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.*/package webservice.axis.test.batClient;public class HelloWorldSoapBindingStub extends org.apache.axis.client.Stub implements webservice.axis.test.batClient.HelloWorld private java.util.Vector cachedSerClasses = new java.util.Vector();private java.util.Vector cachedSerQNames = new java.util.Vector();private java.util.Vector cachedSerFactories = new java.util.Vector();private java.util.Vector cachedDeserFactories = new java.util.Vector();static org.apache.axis.description.OperationDesc _operations;static _operations = new org.apache.axis.description.OperationDesc1; _initOperationDesc1();private static void _initOperationDesc1()org.apache.axis.description.OperationDesc oper; org.apache.axis.description.ParameterDesc param;oper = new org.apache.axis.description.OperationDesc(); oper.setName(hello);oper.setReturnType(new javax.xml.namespace.QName(http:/www.w3.org/2001/XMLSchema, string);oper.setReturnClass(java.lang.String.class);oper.setReturnQName(new javax.xml.namespace.QName(, helloReturn); oper.setStyle(org.apache.axis.constants.Style.RPC);oper.setUse(org.apache.axis.constants.Use.ENCODED); _operations0 = oper;public HelloWorldSoapBindingStub() throws org.apache.axis.AxisFault this(null);public HelloWorldSoapBindingStub(.URL endpointURL, javax.xml.rpc.Service service)throws org.apache.axis.AxisFault this(service); super.cachedEndpoint = endpointURL;throwspublic HelloWorldSoapBindingStub(javax.xml.rpc.Service service) org.apache.axis.AxisFault if (service = null) super.service = new org.apache.axis.client.Service(); else super.service = service; (org.apache.axis.client.Service)super.service).setTypeMappingVersion(1.2);protected org.apache.axis.client.Call createCall() throws java.rmi.RemoteException try org.apache.axis.client.Call _call = super._createCall();if (super.maintainSessionSet) _call.setMaintainSession(super.maintainSession);if (super.cachedUsername != null) _call.setUsername(super.cachedUsername);if (super.cachedPassword != null) _call.setPassword(super.cachedPassword);if (super.cachedEndpoint != null) _call.setTargetEndpointAddress(super.cachedEndpoint);if (super.cachedTimeout != null) _call.setTimeout(super.cachedTimeout);if (super.cachedPortName != null) _call.setPortName(super.cachedPortName);java.util.Enumeration keys = super.cachedProperties.keys(); while (keys.hasMoreElements() java.lang.String key = (java.lang.String) keys.nextElement(); _call.setProperty(key, super.cachedProperties.get(key);return _call;catch (java.lang.Throwable _t) throw new org.apache.axis.AxisFault(Failure trying to get the Call object, _t);public java.lang.String hello() throws java.rmi.RemoteException if (super.cachedEndpoint = null) throw new org.apache.axis.NoEndPointException();org.apache.axis.client.Call _call = createCall(); _call.setOperation(_operations0);_call.setUseSOAPAction(true); _call.setSOAPActionURI();_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setOperationName(newjavax.xml.namespace.QName(http:/test.axis.webservice, hello);setRequestHeaders(_call); setAttachments(_call);try java.lang.Object _resp = _call.invoke(new java.lang.Object );if (_resp instanceof java.rmi.RemoteException) throw (java.rmi.RemoteException)_resp;else extractAttachments(_call);try return (java.lang.String) _resp; catch (java.lang.Exception _exception) return (java.lang.String) org.apache.axis.utils.JavaUtils.convert(_resp, java.lang.String.class); catch (org.apache.axis.AxisFault axisFaultException) throw axisFaultException;最后要感谢网上资源
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸设计 > 毕设全套


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!