好了现在我们将webservice的实现代码发布到tomcat的axis web应用中。如将你的代码拷贝到axis/WEB-INF/classes下
进入你的deploy.wsdd所在目录。
cd C:\tomcat5\webapps\axis\WEB-INF\classes\com\yy\ws
输入如下命令:
C:\tomcat5\webapps\axis\WEB-INF\classes\com\yy\ws> java org.apache.axis.client.AdminClient deploy.wsdd
AdminClient -一个axis发布工具,会自动地将你的webservice发布到WEB-INF下的server-config.wsdd文件中。如果显示:
Processing file deploy.wsdd
<Admin>Done processing</Admin>
则表示发布成功!
好了,现在我们已经完成了创建和发布过程,接下来我们来进行最后一步工作——调用我们写的webservice!
java 代码
1. package com.yy.ws.test;
2.
3. import java.net.MalformedURLException;
4. import java.rmi.RemoteException;
5.
6. import javax.xml.rpc.ServiceException;
7.
8. import com.yy.ws.ClientRequest;
9. import com.yy.ws.MobileBoss;
10. import com.yy.ws.MobileBossService;
11. import com.yy.ws.MobileBossServiceLocator;
12. import com.yy.ws.ServerResponse;
13.
14. public class Test {
15. public static void main(String args[]) throws ServiceException, MalformedURLException, RemoteException{
16. ClientRequest req = new ClientRequest();
17. req.setAmount(1000);
18. req.setOpType("charge");
19. req.setPhoneNumber("13912345678");
20. MobileBossService sl = new MobileBossServiceLocator();
21. //URL url = new URL("http://localhost:8080/axis/services/MobileBoss");
22. //s.getMobileBoss(url);
23. MobileBoss mb = sl.getMobileBoss();//default port
24. ServerResponse resp = mb.charge(req);
25. System.out.println("client result:"+resp.getResultCode()+"\nclient message:"+resp.getMessage());
26. }
27. }
结果如下:
服务器端显示:
13912345678|charge|1000
13912345678is charged successfully!
客户端显示:
client result:8888
client message:13912345678|charge|1000
服务器段成功返回消息,大功告成!不是很难吧?!这篇文章的所有代码我都测试过,全部可以直接使用。希望能够对大家有所帮助。
7 楼 zengqc 2011-03-03 15:03
Processing file deploy.wsdd
Exception: AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.net.ConnectException: Connection refused: connect
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.net.ConnectException: Conne
ction refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
ketFactory.java:153)
at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSoc
ketFactory.java:120)
at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:1
91)
at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.ja
va:404)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrateg
y.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:1792)
at org.apache.axis.client.AdminClient.process(AdminClient.java:439)
at org.apache.axis.client.AdminClient.process(AdminClient.java:404)
at org.apache.axis.client.AdminClient.process(AdminClient.java:410)
at org.apache.axis.client.AdminClient.process(AdminClient.java:320)
at org.apache.axis.client.AdminClient.main(AdminClient.java:463)
{http://xml.apache.org/axis/}hostname:zqc
6 楼 codermouse 2010-09-17 13:52
我用 java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient -lhttp://localhost:7001/axis/services/MobileBusiness deploy.wsdd
就成功了。估计是和我tomcat的端口改成7001有关系。
5 楼 codermouse 2010-09-17 09:21
我在用java org.apache.axis.client.AdminClient deploy.wsdd 命令发布服务的时候报异常:
Exception: AxisFault
faultCode: {http://xml.apache.org/axis/}HTTP
faultSubcode:
faultString: (401)Unauthorized
faultActor:
faultNode:
faultDetail:
{}:return code: 401
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>401 Unauthorized</TITLE>
</HEAD><BODY><H1>Unauthorized</H1>
</BODY></HTML>
{http://xml.apache.org/axis/}HttpErrorCode:401
是不是我哪里没有配置呢?看异常好像是没有授权的意思。这是什么错呢?
请LZ帮忙。谢谢。
4 楼 zhangli123123 2010-08-20 15:28
3 楼 dongtianlaile 2010-07-20 16:30
2 楼 zd125735 2010-06-24 14:03
1 楼 mangliuxiao 2009-09-18 17:05