ITeye博客

一个简单的webservice构建

yuanyannan · 2011-07-15 15:37 · 编程语言 · Markdown

一个简简单单的webservice例子。可以编写测试类,也可以在浏览器输入http://localhost:8989/webservice/services测试webservice是否配置成功。

后台方法: package com.yyn; /**

  • 测试方法
  • @author Andy
  • */ public class Login { public String Add(String str){ return "yyn"+str; }

} server-config.wsdd文件的配置:

web.xml文件配置:

AxisServlet org.apache.axis.transport.http.AxisServlet AxisServlet /services/ AxisServlet /servlet/AxisServlet AxisServlet .jws index.jsp

测试客户端: package com.yyn; import javax.xml.rpc.ServiceException; import org.apache.axis.client.Call; import org.apache.axis.client.Service; /**

  • @author Andy
  • */ public class TestClient {
    public static void main(String args) throws Exception {
    String url = "http://localhost:8989/webservice/services/Login.jws";
    Service service = new Service(); Call call; try { call = (Call) service.createCall(); call.setTargetEndpointAddress(new java.net.URL(url) ); call.setOperationName("Add" );// 这是要调用的方法 String res = (String) call.invoke( new Object{"boy!"} ); System.out.println(res); } catch (ServiceException e) { e.printStackTrace(); } } }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。