当前位置:首页 > 开发 > 编程语言 > Web Service > 正文

jdk 发布 webservice

发表于: 2015-07-13   作者:chun521521   来源:转载   浏览:
摘要:   本文为原创:   1.web.xml:配置ws发布的服务器IP或域名,以及servlet    <context-param>  <param-name>host</param-name>  <param-value>192.168.1.123</pa

 

本文为原创:

 

1.web.xml:配置ws发布的服务器IP或域名,以及servlet

 

 <context-param>
  <param-name>host</param-name>
  <param-value>192.168.1.123</param-value>
 </context-param>
 <servlet>
  <description>This is the description of my J2EE component</description>
  <display-name>My J2EE component</display-name>
  <servlet-name>MainServlet</servlet-name>
  <servlet-class>com.free.app.servlet.MainServlet</servlet-class>
  <load-on-startup>0</load-on-startup>
 </servlet>

 <servlet-mapping>
  <servlet-name>MainServlet</servlet-name>
  <url-pattern>/servlet/MainServlet</url-pattern>
 </servlet-mapping>

 

2.servlet设置

public class MainServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;

 @Override
 public void init() throws ServletException {
  super.init();
  
  ServletContext sc = this.getServletContext();
  String host = sc.getInitParameter("host");
  
  IBussService ws = new BussService();
  Endpoint.publish("http://" + host + "/ws/bussService", ws);
 }

........................

}

 

3.ws实现类

@WebService
public class BussService implements IBussService{
 
 @Override
 @WebMethod
 public String test(String xml) throws Exception {
  
  System.out.println("参数="+xml);
  return Common.succMsg;
 }

}

 

4.xfire调用wsdl

import java.net.URL;

import org.codehaus.xfire.client.Client;

 

public Object[] invoikWS(String url, String method, Object[] params) throws Exception {
  Client client = null;
  client = new Client(new URL(url));
  Object[] result = client.invoke(method, params);
  return result;
 }

 

 

 

 

  

 

 

jdk 发布 webservice

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号