本地搭建NC环境,实现代码开发工作

本地搭建NC环境,实现代码开发工作
1、下载eclipse和NC5.7,配置好jdk路径32位

image-20230207151238069

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FAz4pD9Z-1676538582055)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207151254390.png)]

2、拉取nc项目代码
3、配置环境

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HTInojbM-1676538582056)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207135835551.png)]
在这里插入图片描述

4、启动服务端和客户端

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-qH5fhyKx-1676538582056)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207140104859.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5h8WLaSS-1676538582057)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207140150686.png)]

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

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fHnFPy4N-1676538582057)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207141441919.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-i9cidObX-1676538582058)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207141506699.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-s4fMvw82-1676538582058)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207141553157.png)]

6、部署接口服务
6.1 导出补丁,把接口代码放到nchome里面

在这里插入图片描述

6.2 把导出的nc压缩包的modules文件夹放到nc的根目录下,替换原先的modules文件夹

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-T81eDCaq-1676538582059)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207142245318.png)]

6.3 执行%nchome%\bin\ncSysConfig.bat

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jrPBbJpR-1676538582059)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207142439584.png)]

6.4 点击部署EJB, 等待部署完成

注意:需要先关闭eclipse,不然部署会失败

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7TZtwXon-1676538582059)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207142533244.png)]

7、使用SOAP UI 工具测试接口
7.1启动中间件后, 访问localhost/uapws/service
7.2 找到测试的接口, 然后复制接口地址

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pG2ragmD-1676538582060)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207143825752.png)]

7.3 使用webservice接口测试工具SOAP UI ,进行测试

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VoAMMADd-1676538582060)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207144501966.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7avEb4gw-1676538582061)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207144629530.png)]

8、在项目中测试接口-使用wsimport命令
8.1 使用wsimport命令生成的本地java代码

http://localhost/uapws/service/nc.itf.webapi.Test?wsdl

8.2 把生成的代码移动到项目中

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-aS2pgDZZ-1676538582061)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207150700482.png)]

8.3 测试接口
@RequestMapping("/test2")
    public String test2()  {
        Test_Service test_service = new Test_Service();
        String result = test_service.getTestSOAP11PortHttp().test("ddadfa");
        return result;
    }

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XZo21T3r-1676538582062)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207151343199.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lqi7jglM-1676538582062)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207151410300.png)]

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;
}
9.3 调用接口

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-sXsXLymK-1676538582062)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207151910376.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-r3QtaARC-1676538582062)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20230207151939665.png)]