利用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
set Java_Cmd=java -dirs=%Axis_Lib%
set Axis_Servlet=localhost:8090/myAxis/services/HelloWorld?wsdl
%Java_Cmd% org.apache.axis.wsdl.WSDL2Java -u %Axis_Servlet%
备注:红字体我的axis的目录,也就是刚才我解压出来的axis,
      蓝是我的webservice的访问地址,其他的不用处理,
然后双击这个文件,产生以下几个文件:
(1)、目录是:C:\localhost\myAxis\services\HelloWorld
(2)、
四、 将这四个文件拷贝到你的客户端,创建客户端
运行即可
附录代码:
服务端
HelloWorld.java
package st;
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 st.batClient;
public interface HelloWorld i.Remote {
    public java.lang.String hello() i.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 st.batClient;
public interface HelloWorldService l.rpc.Service {
    public java.lang.String getHelloWorldAddress();
    public st.batClient.HelloWorld getHelloWorld() l.rpc.ServiceException;
    public st.batClient.HelloWorld getHelloWorld(java.URL portAddress) l.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 st.batClient;
public class HelloWorldServiceLocator extends org.apache.axis.client.Service implements st.batClient.HelloWorldService {
    public HelloWorldServiceLocator() {
    }
    public HelloWorldServiceLocator(org.apache.axis.EngineConfiguration config) {
        super(config);
    }
    public HelloWorldServiceLocator(java.lang.String wsdlLoc, l.namespace.QName sName) l.rpc.ServiceException {
        super(wsdlLoc, sName);
    }
    // Use to get a proxy class for HelloWorld
    private java.lang.String HelloWorld_address = "localhost:8090/myAxis/services/HelloWorld";
    public java.lang.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 HelloWorldWSDDServiceName;
    }
    public void setHelloWorldWSDDServiceName(java.lang.String name) {
        HelloWorldWSDDServiceName = name;
    }
    public st.batClient.HelloWorld getHelloWorld() l.rpc.ServiceException {
      java.URL endpoint;
        try {
            endpoint = new java.URL(HelloWorld_address);
        }
        catch (java.MalformedURLException e) {
            throw l.rpc.ServiceException(e);
        }
        return getHelloWorld(endpoint);
    }
    public st.batClient.HelloWorld getHelloWorld(java.URL portAddress) l.rpc.ServiceException {
        try {
            st.batClient.HelloWorldSoapBindingStub _stub = new st.batClient.HelloWorldSoapBindingStub(portAddress, this);
            _stub.setPortName(getHelloWorldWSDDServiceName());
            return _stub;
        }
        catch (org.apache.axis.AxisFault e) {
如何生成webservice客户端            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.
    */
    i.Remote getPort(Class serviceEndpointInterface) l.rpc.ServiceException {

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。