1. 服务端
web服务器: Tomcat5.5, 用到Axis2 1_4_1 (http://apache.mirror.phpchina.com/ws/axis2/1_4_1/
)
取其下webapps下的axis
文件夹.放到Tomcat /webapps下.
写一个要发布的的java类
public class Hello{
public String sayHello(String name){
return "你好,"+name;
}
}
将该文件(Hello.java)改名为Hello.jws
并拷贝到Tomcat 的 webapps\axis下.
下面我们就可以测试该Web服务:
启动Tomcat, 打开浏览器并输入刚刚创建的文件名对应的URL地址 http://localhost:8089/axis/Hello.jws
点击可以查看到WSDL文档,如下
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://localhost:8089/axis/Hello.jws" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost:8089/axis/Hello.jws" xmlns:intf="http://localhost:8089/axis/Hello.jws" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
<wsdl:message name="sayHelloResponse">
<wsdl:part name="sayHelloReturn" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="sayHelloRequest">
<wsdl:part name="name" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="Hello">
<wsdl:operation name="sayHello" parameterOrder="name">
<wsdl:input message="impl:sayHelloRequest" name="sayHelloRequest"/>
<wsdl:output message="impl:sayHelloResponse" name="sayHelloResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloSoapBinding" type="impl:Hello">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHello">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="sayHelloRequest">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://DefaultNamespace" use="encoded"/>
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8089/axis/Hello.jws" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloService">
<wsdl:port binding="impl:HelloSoapBinding" name="Hello">
<wsdlsoap:address location="http://localhost:8089/axis/Hello.jws"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
webservices服务端发布完毕.
------------------------------------------------------------------------------------------------------------------------------
webservices客户端
根据wsdl文件生成java文件
1. 新建一文件夹用于保存下列文件和文件夹.
2. 下载WSDL文档, 保存为xml格式,取名为wsdl.xml
.
3. 新建一个wsdl2java.bat文件,输入
set Axis_Lib=lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
set Output_Path=class
set Package=com.axisws.client
%Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o %Output_Path% -p %Package% wsdl.xml
备注: Axis_Lib
设置你的axis相关jar包,可以是绝对路径, 本例jar包放在本目录下的lib文件夹下.
Output_Path
为输出java文件的路径,可以为绝对路径, 本例生成到本目录下的class文件夹下.
Package
为生成文件的默认包名.
最后的wsdl.xml
为你下载的WSDL文档.
4. 在本目录下的lib文件夹下放入下列jar包(11个, 都在下载的Axis2 1_4_1的lib下)
activation.jar axis.jar axis-ant.jar commons-discovery-0.2.jar commons-logging-1.0.4.jar
jaxrpc.jar log4j-1.2.8.jar mailapi_1_3_1.jar saaj.jar wsdl4j-1.5.1.jar xml-apis-2.6.2.jar
5. 文件夹包含 : wsdl.xml wsdl2java.bat lib文件夹
运行批处理文件后, 会生成一个class文件夹.文件夹内就是生成的类文件.
Hello_PortType.java HelloService.java
HelloServiceLocator.java HelloSoapBindingStub.java
6. 测试客户端, 新建java项目, 把生成的文件连包一起导入, lib内的jar包也导入(文件运行需要).
7. 编写测试文件
package com.axisws.client.test;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.axisws.client.HelloServiceLocator;
import com.axisws.client.Hello_PortType;
public class TestAxisClient {
public static void main(String[] args) {
HelloServiceLocator service = new HelloServiceLocator();
Hello_PortType hello = null;
try {
hello = service.getHello();
System.out.println(hello.sayHello("Tom"));
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
运行得到: 你好,Tom
分享到:
相关推荐
包括3本Axis2的书(英文),實為2本(第1本有...1.Developing Web Services with Apache CXF and Axis2, 3rd Edition 2.Packt.Publishing.Quickstart.Apache.Axis2 3.Develop Web Services With Apache Axis2 PDF格式
Chapter 1, Apache Web Services and Axis2 - Gives you an introduction to web services and the web service stack at Apache. Chapter 2, Looking inside Axis2 - Learn about Axis2 architecture and the ...
Extensive and detailed coverage of the enterprise ready Apache Axis2 Web Services / SOAP / WSDL engine. Attain a more flexible and extensible framework with the world class Axis2 architecture. Learn ...
Apache Axis2 Web Services 2nd Edition
NULL 博文链接:https://topmanopensource.iteye.com/blog/423897
用Apache AXIS 开发 Web Services Step By Step
Develop Web Services With Apache Axis
资源名称:Apache Axis使用方法 (版本1.4)内容简介: Apache Axis是开源的SOAP服务器和客户端。SOAP是网络间不同语言的程序进行交互的方法。SOAP通常在HTTP上交换信息:客户端POST一个SOAP请求,然后接受HTTP响应,...
用axis2开发webService服务器端和客户端例子
axis1.4生成访问客户端代码
Web服务框架 Apache Axis
Entwickler Press - Java Web Services Mit Apache Axis2 有点老,但比较详细介绍了axis2的使用和基本概念。是一本入门的好书
java axis Webservices实例
Apache Web Services Axis2(1.4.1) 详细经典入门实例,使用Eclipse Axis Plug-in,图文并茂,一看就明。
axis生成webservice服务端和客户端详细说明及实例
基于java的开发源码-Web服务框架 Apache Axis.zip 基于java的开发源码-Web服务框架 Apache Axis.zip 基于java的开发源码-Web服务框架 Apache Axis.zip 基于java的开发源码-Web服务框架 Apache Axis.zip 基于java的...
axis 客户端axis 客户端axis 客户端axis 客户端axis 客户端axis 客户端axis 客户端axis 客户端axis 客户端axis 客户端axis 客户端axis 客户端axis 客户端axis 客户端axis 客户端
WebServices With Apache Axis[2008年出版E文版] Develop[1].Web.Services.With.Apache.Axis.2008.zip
Web Service WebService Axis一个完整的客户端代码
axis根据服务端wsdl生成客户端工具。