NC发布与调用WebService接口

NC发布与调用WebService接口

一、发布WebService接口

1.创建接口

1.1.接口定义

package cn.yonyou.ws.itfs;

import cn.yonyou.ws.dto.WxUserDTO;

public interface IWxTestWebService {

public String sayHello(WxUserDTO wxUserDTO);

}

1.2.接口实现

package cn.yonyou.ws.impl;

import cn.yonyou.ws.dto.WxUserDTO;

import cn.yonyou.ws.itfs.IWxTestWebService;

public class WxTestWebServiceImpl implements IWxTestWebService{

@Override

public String sayHello(WxUserDTO wxUserDTO) {

return "nc service say hello -> " + wxUserDTO.toString();

}

}

1.3.请求DTO

package cn.yonyou.ws.dto;

import java.io.Serializable;

public class WxUserDTO implements Serializable {

private static final long serialVersionUID = 1L;

private String name;

private Integer age;

public WxUserDTO() {

}

public WxUserDTO(String name, Integer age) {

super();

this.name = name;

this.age = age;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Integer getAge() {

return age;

}

public void setAge(Integer age) {

this.age = age;

}

@Override

public String toString() {

return "WxUserDTO [name=" + name + ", age=" + age + "]";

}

}

1.4 工程结构

2.upm文件

2.1 ws_test.upm

cn.yonyou.ws.itfs.IWxTestWebService

cn.yonyou.ws.impl.WxTestWebServiceImpl

/cn/yonyou/ws/itfs/IWxTestWebService.wsdl

/cn.yonyou.ws.itfs.IWxTestWebService

注意:wsdl标签和address标签中尽量配置成与接口的全限定名一样,否则请求时请求不到接口(必须这么写)

2.2 upm文件复制至home

将 upm 文件拷贝一份到 nchome/modules/当前ws接口所属模块的模块名/META-INF 下

2.3启动参数中添加uapws

-Duap.hotwebs=nccloud,fs,uapws

2.4 检查ws文件是否生成

启动工程,查看 nchome/temp/wsgen/ 目录下是否生成了 wsdl 文件

2.5 浏览器测试是否正常

http://ip:端口/uapws/service/upm文件中配置的接口地址?wsdl

当前案例地址:

http://127.0.0.1:8090/uapws/service/cn.yonyou.ws.itfs.IWxTestWebService?wsdl

二、调用WebService接口

1.创建maven工程,添加 axis 的依赖

axis

axis

1.4

2.通过生成的代码调用WebService接口,将生成的代码复制到工程中

3.代码

public static void main(String[] args) throws Exception {

IWxTestWebServiceLocator locator = new IWxTestWebServiceLocator();

URL url = new URL("http://127.0.0.1:8065/uapws/service/nc.ws.test.inter.IWxTestWebService");

IWxTestWebServiceSOAP11BindingStub stub = (IWxTestWebServiceSOAP11BindingStub)locator.getIWxTestWebServiceSOAP11port_http(url);

WxUserDTO userDTO = new WxUserDTO("Wish", 18);

String result = stub.doBusiness(userDTO);

System.out.println(result);

}

4.运行结果

相关推荐