本地搭建NC环境,实现代码开发工作
本地搭建NC环境,实现代码开发工作
1、下载eclipse和NC5.7,配置好jdk路径32位
2、拉取nc项目代码
3、配置环境
4、启动服务端和客户端
5、开发接口服务
5.1 新建测试接口和对应的实现类
5.2 编写upm文件
<?xml version='1.0' encoding='UTF-8'?>
<module name="xljt">
<public>
<component remote="true" singleton="true" tx="CMT">
<interface>nc.itf.webapi.Test</interface>
<implementation>nc.impl.xljt.TestServiceImpl</implementation>
<extension class="nc.uap.ws.deploy.OxbWSExtensionProcessor">
<wsdl>/nc/itf/webapi/Test.wsdl</wsdl>
<address>/nc.itf.webapi.Test</address>
</extension>
</component>
</public>
</module>
5.2 生成wsdl文件
5.3 public web services
、
6、部署接口服务
6.1 导出补丁,把接口代码放到nchome里面
6.2 把导出的nc压缩包的modules文件夹放到nc的根目录下,替换原先的modules文件夹
6.3 执行%nchome%\bin\ncSysConfig.bat
6.4 点击部署EJB
, 等待部署完成
注意:需要先关闭eclipse,不然部署会失败
7、使用SOAP UI 工具测试接口
7.1启动中间件后, 访问localhost/uapws/service
7.2 找到测试的接口, 然后复制接口地址
7.3 使用webservice接口测试工具SOAP UI ,进行测试
8、在项目中测试接口-使用wsimport命令
8.1 使用wsimport命令生成的本地java代码
http://localhost/uapws/service/nc.itf.webapi.Test?wsdl
8.2 把生成的代码移动到项目中
8.3 测试接口
@RequestMapping("/test2")
public String test2() {
Test_Service test_service = new Test_Service();
String result = test_service.getTestSOAP11PortHttp().test("ddadfa");
return result;
}
9、在项目中测试接口-引入第三方依赖包
9.1导入依赖
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-saaj</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.3</version>
</dependency>
9.2 编写调用wsdl服务代码
@RequestMapping("/test")
public String test() {
String result = null;
try {
Service service = new Service();
Call call = (Call) service.createCall();
// wsdl完整地址
call.setTargetEndpointAddress(new URL("http://localhost/uapws/service/nc.itf.webapi.Test"));
/**
* 设置方法名
* new QName(String namespaceURI, String localPart) namespaceURI即为wsdl中的targetNamespace, localPart即为接口名
*/
call.setOperationName(new QName("test"));
/**
* 添加参数
* addParameter方法的参数包括:参数名(namespace+参数名)、参数类型、ParameterMode(入参即为IN)
*/
call.addParameter("string", XMLType.XSD_STRING, ParameterMode.IN);
// call.setUseSOAPAction(true);
// SOAPActionURI格式为targetNamespace+方法名
// call.setSOAPActionURI("http://webapi.itf.nc/Test/test");
// 指定返回值类型,为字符串
call.setReturnType(XMLType.XSD_STRING,String.class);
result = (String) call.invoke(new Object[]{"手机号码"});
System.out.println(result);
} catch (Exception e) {
throw new RuntimeException(e);
}
return result;
}