使用jws生成webservice 例子

1:建一个webservice接口 自定义一个方法
@WebService
public interface IPushInfo {

@WebMethod
public String pushInfo(@WebParam(name ="data") String data);

}

2:实现接口,实现方法
@WebService(endpointInterface=”crm_lhx.webservice.IPushInfo”)
public class PushInfoImp implements IPushInfo {

@Override
public String pushInfo(String data) {
    System.out.println("webservice 入参...." + data);
    return "info..." + data;
}

public static void main(String[] args) {
    //发布webservice
    Endpoint.publish("http://192.168.2.70/pushInfo",new PushInfoImp());
}

}

3:发布接口 路径自定义

public static void main(String[] args) {
    //发布webservice
    Endpoint.publish("http://192.168.2.77/pushInfo",new PushInfoImp());
}

运行后再浏览器输入地址校验
http://192.168.2.77/pushInfo?wsdl

#######webservice 客户端调用

1:用wsimport 命令生成代码
cmd运行 然后切换到指定的目录,这样生成的java文件也在该目录下面

执行命令
wsimport -keep -p com.demo.client http://192.168.2.77/pushInfo?wsdl

然后把生成的java文件copy到对应的程序中
//客户端代码

public class PushInfoClient {

    public static void main(String[] args) {
// PushInfoImpService 这个是根据 wsdl 用命令自动生成的文件,w
    PushInfoImpService server = new PushInfoImpService();
    String string = server.getPushInfoImpPort().pushInfo("hello!");
    System.out.println(string);
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值