第一范文网 - 专业文章范例文档资料分享平台

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

来源:用户分享 时间:2025/6/10 9:15:01 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

利用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 -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\\services\\HelloWorld (2)、

四、

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

运行即可

附录代码: 服务端

HelloWorld.java

package webservice.axis.test;

public class HelloWorld { public String hello(){ return \+\;

}

}

客户端(通过刚才命令生成的四个文件) 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();

public webservice.axis.test.batClient.HelloWorld getHelloWorld()

throws

javax.xml.rpc.ServiceException;

public webservice.axis.test.batClient.HelloWorld getHelloWorld(java.net.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 HelloWorld private java.lang.String HelloWorld_address = \

public java.lang.String getHelloWorldAddress() { return HelloWorld_address; }

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

private java.lang.String HelloWorldWSDDServiceName = \

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 { java.net.URL endpoint; try {

endpoint = new java.net.URL(HelloWorld_address); }

catch (java.net.MalformedURLException e) {

throw new javax.xml.rpc.ServiceException(e); }

return getHelloWorld(endpoint); }

public webservice.axis.test.batClient.HelloWorld getHelloWorld(java.net.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 java.net.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(\is no stub implementation for the interface: \ }

/**

* 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 (\ 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 new javax.xml.namespace.QName(\\

搜索更多关于: 使用axis自动生成webservice客户端代码 的文档
使用axis自动生成webservice客户端代码.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c6o96z1sclj5dq8n1sb2s_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top