最近研究axis的webservice 有个位搞不定 ,卡啦一天发出来请大家帮忙解决下!
是这样,service端我都配好了,deploy.wsdd的文件如下:
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name="HelloWord" provider="java:RPC"> <parameter name="className" value="resunly.service.HelloWord" /> <parameter name="allowedMethods" value="*" /> </service> </deployment>
在cmd 下也生成啦 相应的 server-config.wsdd 文件,然后写类:HelloWrod 代码如下:
package resunly.service; public class HelloWrod { public HelloWrod(){ } public String hello(String name){ return "hello"+name; } public int getNum(int num,int end){ return num+end; } }
并将此类生成的class文件放到了E:\Program\tomcat\apache-tomcat-6.0.18\webapps\axis\WEB-INF\classes\resunly\service 下,客户端的的调用代码如下:
package resunly.client; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; import javax.xml.namespace.QName; import javax.xml.rpc.ServiceException; import org.apache.axis.client.Call; import org.apache.axis.client.Service; public class TestWebService { /** * @param args */ public static void main(String[] args) { String SeverAdd = "http://localhost:8080/axis/resunly/service/HelloWord"; Service service = new Service(); try { Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new URL(SeverAdd)); // call.setOperationName(new QName(SeverAdd,"hello")); // String result = (String)call.invoke(new Object[]{"resunly"}); // System.out.println(result); call.setOperationName(new QName(SeverAdd,"getNum")); Integer res = (Integer)call.invoke(new Object[]{new Integer(1),new Integer(3)}); System.out.println(res); } catch (ServiceException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } } }
然后,run 就报错!报错内容如下:
AxisFault faultCode: {http://xml.apache.org/axis/}HTTP faultSubcode: faultString: (404)Not Found faultActor: faultNode: faultDetail: {}:return code: 404 <html><head><title>Apache Tomcat/6.0.18 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - /axis/resunly/service/HelloWord</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>/axis/resunly/service/HelloWord</u></p><p><b>description</b> <u>The requested resource (/axis/resunly/service/HelloWord) is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.18</h3></body></html> {http://xml.apache.org/axis/}HttpErrorCode:404 (404)Not Found at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744) at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144) at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.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:2443) at org.apache.axis.client.Call.invoke(Call.java:2366) at org.apache.axis.client.Call.invoke(Call.java:1812) at resunly.client.TestWebService.main(TestWebService.java:29)
提示是在 Integer res = (Integer)call.invoke(new Object[]{new Integer(1),new Integer(3)});
这里报的错 ,上面注释的也是在这里报的错,不知道为什么 ,卡啦半天搞不定啦 ,求指点 ,感激不尽!