NC WebService开发参考

1.1发布web service

NC5.5以上的版本,都内建了uapws模块,利用该模块要发布一个webservice非常方便。只需要完成以下几个步骤即可,这里将用一系列的例子来说明。

  1. 创建一个接口,如

nc.ws.intf.IHelloService.java

package nc.ws.intf;

 

public interface IHelloService {

    public String hello(String str);

}

 

  1. 然后建立这个接口的实现类:

nc.ws.impl.HelloImpl.java

package nc.ws.impl;

 

import nc.ws.intf.IHelloService;

 

public class HelloImpl implements IHelloService {

 

    public String hello(String str) {

        return "hello " + str;

    }

 

}

 

  1. 将这个接口作为web Service发布到nc系统中,发布的原理是:在一个upm文件中声明一个public component, 这个component将会在nc启动后加载到容器中,外部系统即可通过调用uapws的servlet来调用这个component暴露的方法。具体发布的方法是,先安装nc webservice eclipse插件(内网可到\\uapserver03\webdir上下载nc.uap.mde.wstools_1.0.3.jar,拷贝到eclipse的plugins目录然后重启eclipse).

 

安装完插件后在接口类IHelloService.java处点右键,选择WS Tools-> publish Web Service,将弹出一个向导。

 

填写一个新的upm文件或选择一个已存在的upm文件,然后点next>

 

在这个界面中,只需要填写 实现类的类名即可,接口已经自动填写好了,其它设置都用默认的。继续点击next> 进入下图的界面

这个界面无需填写任何设置。关键的 Extension class设置和 WSDL location以及 Address都已经自动填写了,而Interceptors是很少使用的配置,一般不用填写。

 

再次点击Next进入下一个页面。

 

 

这个界面用于配置web service的安全,(默认的是否要求认证授权是勾选上的。)一个接口发布为web service后,往往可以使用认证授权、签名、加密等方法来保障web service的安全,而web service安全的实现比较复杂,在该文档中将一步步展来话明。 这里选实现一个不带任何安全选项的web service:将Web Service的安全配置选项全部不勾选。如上图选示,然后点击Finish即可。

 

发布完成后将在eclipse的项目下建立一个名为ws的源文件夹,并在nc.ws.intf包下生成IHelloService.wsdl的文件,该文件描述了HelloService提供的所有功能和调用方法。由于这是一个最简单的Web Service,还不涉用传入参数和返回值是复杂VO的情况,所以生成的文件暂时只有WSDL文件和一个upm文件。Upm文件位于模块META-INF文件夹下:

 

T_WebService.upm

<?xml version='1.0' encoding='UTF-8'?>

<module>

    <public>

        <component>

            <interface>nc.ws.intf.IHelloService</interface>

            <implementation>nc.ws.impl.HelloImpl</implementation>

            <extension class="nc.uap.ws.deploy.OxbWSExtensionProcessor">

                <wsdl>/nc/ws/intf/IHelloService.wsdl</wsdl>

                <address>/nc.ws.intf.IHelloService</address>

            </extension>

        </component></public>

    <private>

    </private>

</module>

 

生成的WSDL文件是Document Literal风格的,将来客户端调用该Web Service时应该注意一下。

 

IHelloService.wsdl

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"

xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"

xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"

xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"

jaxb:version="2.0"

xmlns:ns0="http://intf.ws.nc/IHelloService"

targetNamespace="http://intf.ws.nc/IHelloService">

 

<jaxws:bindings>

     <jaxws:package name="nc.ws.intf"/>

</jaxws:bindings>

 

<wsdl:types>

   <xsd:schema xmlns:ns="http://intf.ws.nc/IHelloService"

              attributeFormDefault="unqualified"

              elementFormDefault="unqualified"

              targetNamespace="http://intf.ws.nc/IHelloService" jaxb:version="2.0">

     <xsd:annotation>

    <xsd:appinfo>

              <jaxb:schemaBindings>

              <jaxb:package name="nc.ws.intf"/>

         </jaxb:schemaBindings>

         </xsd:appinfo>

     </xsd:annotation>

     <xsd:element name="hello">

         <xsd:complexType>

            <xsd:sequence>

                   <xsd:element name="stringminOccurs="0" nillable="true" type="xsd:string"/>

             </xsd:sequence

         </xsd:complexType>

     </xsd:element>

     <xsd:element name="helloResponse">

         <xsd:complexType>

            <xsd:sequence>

                   <xsd:element name="returnminOccurs="0" nillable="true" type="xsd:string"/>

             </xsd:sequence

         </xsd:complexType>

     </xsd:element>

   </xsd:schema>

</wsdl:types>

    <wsdl:message name="helloRequest">

        <wsdl:part name="parameterselement="ns0:hello"/>

    </wsdl:message>

    <wsdl:message name="helloResponse">

        <wsdl:part name="parameterselement="ns0:helloResponse"/>

    </wsdl:message>

 

    <wsdl:portType name="IHelloServicePortType">

        <wsdl:operation name="hello">

            <wsdl:input message="ns0:helloRequest" wsaw:Action="urn:hello"/>

            <wsdl:output message="ns0:helloResponse" wsaw:Action="urn:helloResponse"/>

        </wsdl:operation>

    </wsdl:portType>

   

   

    <wsdl:binding name="IHelloServiceSOAP11Binding" type="ns0:IHelloServicePortType">

        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>

        <wsdl:operation name="hello">

            <soap:operation soapAction="urn:hello" style="document"/>

            <wsdl:input>

                <soap:body use="literal"/>

            </wsdl:input>

            <wsdl:output>

                <soap:body use="literal"/>

            </wsdl:output>

        </wsdl:operation>

    </wsdl:binding>

    <wsdl:service name="IHelloService">

        <wsdl:port name="IHelloServiceSOAP11port_http" binding="ns0:IHelloServiceSOAP11Binding">

            <soap:address location="http://localhost/uapws/service/nc.ws.intf.IHelloService"/>

        </wsdl:port>

    </wsdl:service>

</wsdl:definitions>

 

 

1.2 加载web service和查看己发布的web service

 

重启服务器后即可访问该Web Service:打开http://{hostaddress}/uapws即可进入web service控制台(5.5和5.6由于一些问题,该网页不能正常访问。)也可直接进入http://{host address}/uapws/service查看已发布的所有Web Service.

 

在这个页面上可以查看到所有模块中已发布的web service,每个可以查看每个web service的wsdl并对web service进行简单的 soap 消息测试(类似soap ui的工具)。

在http://{host address}/uapws/service页面中列出的service,都是发布成功的服务。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值