axis开发webservice(2)
来源:互联网 发布:iphone刷机助手 mac 编辑:程序博客网 时间:2024/06/02 16:22
package server;
public class SayHello
{
public String getName(String name)
{
return "hello "+name;
}
}
5、编写wsdd文件
deploy.wsdd文件内容如下:
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java=
"http://xml.apache.org/axis/wsdd/providers/java">
<service name="SayHello" provider="java:RPC">
<parameter name="className" value="server.SayHello.getName"/>
<parameter name="allowedMethods" value="*"/>
<parameter name="scope" value="session"/><!-- request, session, or application -->
</service>
</deployment>
6、把工程发布到Tomcat并启动Tomcat;
7、发布服务
编辑一个deploy.bat,Axis_Lib为axis.jar路径。内容如下:
set Axis_Lib=./lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
set Axis_Servlet=http://localhost:8080/AxisTest/servlet/AxisServlet
%Java_Cmd% org.apache.axis.client.AdminClient -l%Axis_Servlet% deploy.wsdd
执行这个批处理文件,这时候,如果提示成功的话,访问http://localhost:8080/AxisTest/servlet/AxisServlet或http://localhost:8080/AxisTest/services就会显示服务列表。
8、生成客户端client stub文件
在浏览器上访问服务器端的服务,可以下载到WSDL文件,通过Axis的相关工具,可以自动从WSDL文件中生成Web Service的客户端代码。
编写一个WSDL2Java.bat文件,其内容如下:
set Axis_Lib=./lib
set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib%
set Output_Path=./src
set Package=server.com
set wsdl_path=http://localhost:8080/AxisTest/services/ SayHello?wsdl
%Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o%Output_Path% -p%Package% %wsdl_path%
执行这个批处理文件就可以生成client stub.
生成的stub client文件列表为:SayHello.java,SayHelloService.java,SayHelloServiceLocator.java,SayHelloSoapBindingStub.java .
9、编写客户端程序,编译并执行
1)、Stubs方式
下面是一段junit测试客户端代码。
import java.net.URL;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class TestWSClient extends TestCase {
public TestWSClient(String string) {
super(string);
}
public void SayHelloClient() throws Exception {
SayHelloService service = new SayHelloServiceLocator();
SayHello_PortType client = service.getSayHello() ;
String retValue = client.getName("clientname");
System.out.println(retValue);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new TestWSClient("SayHelloClient"));
return suite;
}
}
2)、动态调用方式:
try {
// Options options = new Options(args);
String endpointURL = "http://localhost:8080/AxisTest/services/SayHello";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpointURL) );
call.setOperationName( new QName("SayHello", "getName") );
String res = (String) call.invoke( new Object[] {"Jack"} );
System.out.println( res );
} catch (Exception e) {
System.err.println(e.toString());
}
- axis开发webservice(2)
- Axis开发webservice
- 使用Axis开发WebService
- 用AXIS开发WEBSERVICE
- axis开发webservice(1)
- Axis 开发WebService
- 用Axis开发Webservice
- Axis 开发WebService
- 用Axis开发WebService
- axis开发webservice
- Axis 开发webservice
- axis:开发helloworld webservice
- Axis 部署开发WebService
- Axis开发WebService(一)
- Axis开发WebService(二)
- Axis开发WebService 指南
- axis开发webservice
- axis开发webservice
- axis开发webservice(1)
- 触摸MVP
- SPRING数据访问对象(DAO)框架入门
- CPU温度检测的工具
- rico 入门与应用
- axis开发webservice(2)
- Hero
- Boost初识
- 创建eclipse的Web项目的一般步骤
- 关于刘慈欣的若干个标题
- 如何在PC上看HD-DVD光碟
- 等离子电视
- 出场顺序问题的研究(1)--由选秀节目想到的概率问题
- 自动关闭窗体的JS代码