第一个的webservice实例
超简单,才5步
1> 获取axis及关联的jar包
dl.iteye/topics/download/6a76de1e-d506-35bc-a41b-508d4be04025
2> 新建一个模拟服务java类
package server; public class SayHello { public String getName(String name) { return "你好," + name; } } |
3> 在l 下新增一个servelt
<servlet> <servlet-name>AxisServlet</servlet-name> <servlet-class>org.ansport.http.AxisServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> |
4> 在web项目的l 同目录新建文件 server-config.wsdd,自己改改
<?xml version="1.0" encoding="UTF-8"?> <deployment xmlns="/axis/wsdd/" xmlns:java="/axis/wsdd/providers/java"> <globalConfiguration> <parameter name="sendMultiRefs" value="true"/> <parameter name="disablePrettyXML" value="true"/> <parameter name="dotNetSoapEncFix" value="true"/> <parameter name="enableNamespacePrefixOptimization" value="false"/> <parameter name="sendXMLDeclaration" value="true"/> <parameter name="sendXsiTypes" value="true"/> <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/> </globalConfiguration> <handler type="java:org.apache.axis.handlers.http.URLMapper" name="URLMapper"/> <service name="Login.jws" provider="java:RPC"> <parameter name="className" value="server.SayHello"/> <parameter name="scope" value="request"/> <parameter name="allowedMethods" value="*"/> <messageReceiver class="org.ivers.RawXMLINOutMessageReceiver"/> </service> <transport name="http"> <requestFlow> <handler type="URLMapper"/> </requestFlow> </transport> </deployment> |
5> 运行tomcat ,如果输入:localhost:8080/项目名/services 如下显示:
说明webservice部署成功。
6> 随便写个客户端,调用吧
package client; import org.apache.axis.client.Call; import org.apache.axis.client.Service; public class TestClient { public static void main(String[] args) throws Exception { 调用webservice服务 // 指出service所在URL String endpoint = "localhost:8080/services/Login.jws"; // 创建一个服务(service)调用(call) Service service = new Service(); Call call = (Call) ateCall();// 通过service创建call对象 // 设置service所在URL call.setTargetEndpointAddress(new java.URL(endpoint)); // 方法名(processService)与MyService.java方法名保持一致 call.setOperationName("getName"); // Object 数组封装了参数,参数为"This is Test!",调用processService(String arg) String ret = (String) call.invoke(new Object[] { "帅哥!" }); System.out.println(ret); } } |
输出结果如下:
作者QQ: 339751607 , 希望各位读者帮我踩踩空间哈,谢谢哈^_*
user.qzone.qq/339751607
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论