随笔-6  评论-1  文章-0  trackbacks-0


package rece.test;

import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.ws.WebServiceContext;
import com.sun.net.httpserver.HttpExchange;


@WebService(targetNamespace = "http://rece.test.com", serviceName = "WebServiceRece")
@SOAPBinding(style = SOAPBinding.Style.RPC)

public class WebServiceRece
{
 @Resource
 private WebServiceContext wsContext;

 @WebMethod
 public String sendZxdxSms(@WebParam(partName = "Username")String userName,
         @WebParam(partName = "Password")String passWord,
         @WebParam(partName = "Content")String content,
         @WebParam(partName = "FromTerminalId")String fromTerminalId,
         @WebParam(partName = "ToTerminalId")String toTerminalId
         )
 {  
  //获取提交请求的IP地址
  HttpExchange exchange  = (HttpExchange)wsContext.getMessageContext().get("com.sun.xml.internal.ws.http.exchange");
  String remortAddress = exchange.getRemoteAddress().getAddress().getHostAddress();
   //具体实现
  return WebServiceReceImpl.getInstance().send(userName, passWord, content, fromTerminalId, toTerminalId,remortAddress);
 }
}

在main方法中启动这个webservice服务:
Endpoint.publish("http://localhost:9898/test/send.jws", new WebServiceRece());

打开wsdl
http://localhost:9898/test/send.jws?wsdl

生成客户端
在命令行下运行wsimport –keep http://localhost:9898/test/send.jws?wsdl,即可在当前目录生成客户端,-keep表示保留源文件,如果没有-keep,则只生成class文件

posted on 2008-04-29 14:52 天堂有路 阅读(1651) 评论(1)  编辑  收藏

评论:
# re: java1.6实现webservice功能[未登录] 2008-05-08 18:21 | steven
请问lz
com.sun.xml.internal.ws.http.exchange
我怎么找不到啊?
谢谢!  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: