2024年1月31日发(作者:)

利用AXIS生成客户端文件,使得开发webservice更加简单,以下是我的个人代码,

工具:

Myeclipse7.0,axis1.4,tomcat5.5,jdk1.5

一、 下载axis的jar包,我的是axis-bin-1_包,解压后有axis的lib目录,一会儿我们要用,

二、 在myeclip se中创建自己的webservice工程,这个在的文库里有,

三、 在C盘目录下创建一个批处理文件,我的名字是,内容如下:

set Axis_Lib=E:jaraxisasixToolaxis-bin-1_4axis-1_4lib

set Java_Cmd=java -=%Axis_Lib%

set Axis_Servlet=localhost:8090/myAxis/services/HelloWorld?wsdl

%Java_Cmd% 2Java -u %Axis_Servlet%

备注:红色字体我的axis的目录,也就是刚才我解压出来的axis,

蓝色是我的webservice的访问地址,其他的不用处理,

然后双击这个文件,产生以下几个文件:

(1)、目录是:C:localhostmyAxisservicesHelloWorld

(2)、

四、 将这四个文件拷贝到你的客户端,创建客户端

运行即可

附录代码:

服务端

package ;

public class HelloWorld {

public String hello(){

return "Hello "+"aaaaaaaaaaaaaaaaaa";

}

}

客户端(通过刚才命令生成的四个文件)

/**

*

*

* This file was auto-generated from WSDL

* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.

*/

package ent;

public interface HelloWorld extends {

public hello() throws Exception;

}

/**

*

*

* This file was auto-generated from WSDL

* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.

*/

package ent;

public interface HelloWorldService extends e {

public getHelloWorldAddress();

public orld getHelloWorld() throws

eException;

public orld getHelloWorld( portAddress)

throws eException;

}

/**

*

*

* This file was auto-generated from WSDL

* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.

*/

package ent;

public class HelloWorldServiceLocator extends e implements

orldService {

public HelloWorldServiceLocator() {

}

public HelloWorldServiceLocator(Configuration config) {

super(config);

}

public HelloWorldServiceLocator( wsdlLoc,

sName) throws eException {

super(wsdlLoc, sName);

}

// Use to get a proxy class for HelloWorld

private HelloWorld_address =

"localhost:8090/myAxis/services/HelloWorld";

public getHelloWorldAddress() {

return HelloWorld_address;

}

// The WSDD service name defaults to the port name.

private HelloWorldWSDDServiceName = "HelloWorld";

public getHelloWorldWSDDServiceName() {

return HelloWorldWSDDServiceName;

}

public void setHelloWorldWSDDServiceName( name) {

HelloWorldWSDDServiceName = name;

}

public orld getHelloWorld() throws

eException {

endpoint;

try {

endpoint = new (HelloWorld_address);

}

catch (medURLException e) {

throw new eException(e);

}

return getHelloWorld(endpoint);

}

public orld getHelloWorld( portAddress)

throws eException {

try {

orldSoapBindingStub _stub = new

orldSoapBindingStub(portAddress, this);

_tName(getHelloWorldWSDDServiceName());

return _stub;

}

catch (ult e) {

return null;

}

}

public void setHelloWorldEndpointAddress( 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 getPort(Class serviceEndpointInterface) throws

eException {

try {

if

(gnableFrom(serviceEndpointInterface)) {

orldSoapBindingStub _stub = new

orldSoapBindingStub(new

(HelloWorld_address), this);

_tName(getHelloWorldWSDDServiceName());

return _stub;

}

}

catch (ble t) {

throw new eException(t);

}

throw new eException("There is no stub implementation for the

interface: " + (serviceEndpointInterface == null ? "null" : e()));

}

/**

* For the given interface, get the stub implementation.

* If this service has no port for the given interface,

* then ServiceException is thrown.

*/

public getPort( portName, Class

serviceEndpointInterface) throws eException {

if (portName == null) {

return getPort(serviceEndpointInterface);

}

inputPortName = alPart();

if ("HelloWorld".equals(inputPortName)) {

return getHelloWorld();

}

else {

_stub = getPort(serviceEndpointInterface);

(() _stub).setPortName(portName);

return _stub;

}

}

public getServiceName() {

return new

("localhost:8090/myAxis/services/HelloWorld",

"HelloWorldService");

}

private t ports = null;

public or getPorts() {

if (ports == null) {

ports = new t();

(new

("localhost:8090/myAxis/services/HelloWorld",

"HelloWorld"));

}

return or();

}

/**

* Set the endpoint address for the specified port name.

*/

public void setEndpointAddress( portName, address) throws

eException {

if ("HelloWorld".equals(portName)) {

setHelloWorldEndpointAddress(address);

}

else

{ // Unknown Port Name

throw new eException(" Cannot set Endpoint Address for

Unknown Port" + portName);

}

}

/**

* Set the endpoint address for the specified port name.

*/

public void setEndpointAddress( portName,

address) throws eException {

setEndpointAddress(alPart(), address);

}

}

/**

*

*

* This file was auto-generated from WSDL

* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.

*/

package ent;

public class HelloWorldSoapBindingStub extends implements

orld {

private cachedSerClasses = new ();

private cachedSerQNames = new ();

private cachedSerFactories = new ();

private cachedDeserFactories = new ();

static ionDesc [] _operations;

static {

_operations = new ionDesc[1];

_initOperationDesc1();

}

private static void _initOperationDesc1(){

ionDesc oper;

terDesc param;

oper = new ionDesc();

e("hello");

urnType(new

("/2001/XMLSchema", "string"));

urnClass();

urnQName(new ("", "helloReturn"));

le();

(D);

_operations[0] = oper;

}

public HelloWorldSoapBindingStub() throws ult {

this(null);

}

public HelloWorldSoapBindingStub( endpointURL, e service)

throws ult {

this(service);

Endpoint = endpointURL;

}

public HelloWorldSoapBindingStub(e service) throws

ult {

if (service == null) {

e = new e();

} else {

e = service;

}

((e)e).setTypeMappingVersion("1.2");

}

protected createCall() throws Exception {

try {

_call = super._createCall();

if (inSessionSet) {

_ntainSession(inSession);

}

if (Username != null) {

_rname(Username);

}

if (Password != null) {

_sword(Password);

}

if (Endpoint != null) {

_getEndpointAddress(Endpoint);

}

if (Timeout != null) {

_eout(Timeout);

}

if (PortName != null) {

_tName(PortName);

}

ation keys = ();

while (eElements()) {

key = () ement();

_perty(key, (key));

}

return _call;

}

catch (ble _t) {

throw new ult("Failure trying to get the Call object", _t);

}

}

public hello() throws Exception {

if (Endpoint == null) {

throw new ointException();

}

_call = createCall();

_ration(_operations[0]);

_SOAPAction(true);

_PActionURI("");

_PVersion(11_CONSTANTS);

_rationName(new

("vice", "hello"));

setRequestHeaders(_call);

setAttachments(_call);

try { _resp = _(new [] {});

if (_resp instanceof Exception) {

throw (Exception)_resp;

}

else {

extractAttachments(_call);

try {

return () _resp;

} catch (ion _exception) {

return () t(_resp,

);

}

}

} catch (ult axisFaultException) {

throw axisFaultException;

}

}

}

最后要感谢网上资源