1、利用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:\jar\axis\asixTool\axis-bin-1_4\axis-1_4\lib
2、 set 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:\localhost\myAxis\ser
3、vices\HelloWorld (2)、 四、 将这四个文件拷贝到你的客户端,创建客户端 运行即可 附录代码: 服务端 HelloWorld.java package webservice.axis.test; public class HelloWorld { public String hello(){ return "Hello "+"aaaaaaaaaaaaaaaaaa"; } } 客户端(通过刚才命令生成的四个文件) HelloWorld.java /** * HelloWorld.java * *
4、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; }
5、 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 {
6、 public java.lang.String getHelloWorldAddress(); public webservice.axis.test.batClient.HelloWorld getHelloWorld() throws javax.xml.rpc.ServiceException; public webservice.axis.test.batClient.HelloWorld getHelloWorld(.URL portAddress) throws javax.xml.rpc.ServiceException; }
7、 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.a
8、xis.client.Service implements webservice.axis.test.batClient.HelloWorldService { public HelloWorldServiceLocator() { } public HelloWorldServiceLocator(org.apache.axis.EngineConfiguration config) { super(config); } public HelloWorldServiceLocator(java.lang.St
9、ring wsdlLoc, javax.xml.namespace.QName sName) throws javax.xml.rpc.ServiceException { super(wsdlLoc, sName); } // Use to get a proxy class for HelloWorld private java.lang.String HelloWorld_address = "http://localhost:8090/myAxis/services/HelloWorld"; public java.la
10、ng.String getHelloWorldAddress() { return HelloWorld_address; } // The WSDD service name defaults to the port name. private java.lang.String HelloWorldWSDDServiceName = "HelloWorld"; public java.lang.String getHelloWorldWSDDServiceName() { return HelloWorldW
11、SDDServiceName; } public void setHelloWorldWSDDServiceName(java.lang.String name) { HelloWorldWSDDServiceName = name; } public webservice.axis.test.batClient.HelloWorld getHelloWorld() throws javax.xml.rpc.ServiceException { .URL endpoint; try {
12、 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 por
13、tAddress) throws javax.xml.rpc.ServiceException { try { webservice.axis.test.batClient.HelloWorldSoapBindingStub _stub = new webservice.axis.test.batClient.HelloWorldSoapBindingStub(portAddress, this); _stub.setPortName(getHelloWorldWSDDServiceName());
14、 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 impl
15、ementation. * 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.HelloW
16、orld.class.isAssignableFrom(serviceEndpointInterface)) { webservice.axis.test.batClient.HelloWorldSoapBindingStub _stub = new webservice.axis.test.batClient.HelloWorldSoapBindingStub(new .URL(HelloWorld_address), this); _stub.setPortName(getHelloWorldWSDDServiceName
17、)); 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: " + (serviceEndpointInter
18、face == 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.n
19、amespace.QName portName, Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException { if (portName == null) { return getPort(serviceEndpointInterface); } java.lang.String inputPortName = portName.getLocalPart(); if ("HelloWorld".equals(inpu
20、tPortName)) { return getHelloWorld(); } else { java.rmi.Remote _stub = getPort(serviceEndpointInterface); ((org.apache.axis.client.Stub) _stub).setPortName(portName); return _stub; } } public javax.xml.namesp
21、ace.QName getServiceName() { return new javax.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 =
22、new java.util.HashSet(); ports.add(new javax.xml.namespace.QName("http://localhost:8090/myAxis/services/HelloWorld", "HelloWorld")); } return ports.iterator(); } /** * Set the endpoint address for the specified port name. */ public void setEn
23、dpointAddress(java.lang.String portName, java.lang.String address) throws javax.xml.rpc.ServiceException { if ("HelloWorld".equals(portName)) { setHelloWorldEndpointAddress(address); } else { // Unknown Port Name throw new javax.xml.rpc.Servic
24、eException(" 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.ServiceExce
25、ption { 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. */ packag
26、e 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.uti
27、l.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.descr
28、iption.OperationDesc[1]; _initOperationDesc1(); } private static void _initOperationDesc1(){ org.apache.axis.description.OperationDesc oper; org.apache.axis.description.ParameterDesc param; oper = new org.apache.axis.description.OperationDesc();
29、 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.
30、axis.constants.Style.RPC); oper.setUse(org.apache.axis.constants.Use.ENCODED); _operations[0] = oper; } public HelloWorldSoapBindingStub() throws org.apache.axis.AxisFault { this(null); } public HelloWorldSoapBindingStub(.URL endpointURL, javax.x
31、ml.rpc.Service service) throws org.apache.axis.AxisFault { this(service); super.cachedEndpoint = endpointURL; } public HelloWorldSoapBindingStub(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault { if (service == null) { super.servic
32、e = 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 {
33、 try { org.apache.axis.client.Call _call = super._createCall(); if (super.maintainSessionSet) { _call.setMaintainSession(super.maintainSession); } if (super.cachedUsername != null) { _call.setUsername(super.cach
34、edUsername); } if (super.cachedPassword != null) { _call.setPassword(super.cachedPassword); } if (super.cachedEndpoint != null) { _call.setTargetEndpointAddress(super.cachedEndpoint); } if
35、 (super.cachedTimeout != null) { _call.setTimeout(super.cachedTimeout); } if (super.cachedPortName != null) { _call.setPortName(super.cachedPortName); } java.util.Enumeration keys = super.cachedProperties.keys();
36、 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) {
37、 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(); }
38、 org.apache.axis.client.Call _call = createCall(); _call.setOperation(_operations[0]); _call.setUseSOAPAction(true); _call.setSOAPActionURI(""); _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS); _call.setOperationName(new jav
39、ax.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.
40、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; } } } 最后要感谢网上资源
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4009-655-100 投诉/维权电话:18658249818