RSS订阅
RSS订阅TT SOA
您现在的位置:TT SOA > SOA中国关键任务 > SOA中的“S”

SOA中的“S”

2008-9-3  选择字号:  | |
打印本文章

导读:关注WebService,SOA的核心理念是"S",即服务。SCA绑定用于包含在SCA域里的引用和服务之间的服务交互。绑定类型以哪种方式被实现没有在SCA规范中定义。

关键词:WebService SOA 服务 SCA 绑定

正在加载数据...

  这些天一直在关注WebService,SOA的核心理念是“S”,即服务。当我们的构件完成之后,究竟如何发布为何种服务,这就设计到了SCA绑定的问题。我这里研究了一下Cxf框架,与大家一同分享,如理解有偏差,请大家指出,谢谢。

  SCA绑定用于包含在SCA域里的引用和服务之间的服务交互。绑定类型以哪种方式被实现没有在SCA规范中定义,它可以被不同的SCA运行时(runtimes)通过不用的方式实现。唯一的要求是:SCA绑定类型中必需的服务必须被实现。

  Web Service绑定的Schema如下:

  <binding.ws wsdlElement="xs:anyURI"?

                      wsdli:wsdlLocation="list of xs:anyURI"?

               ...>

           <wsa:EndpointReference>...</wsa:EndpointReference>*

            ...

       </binding.ws>

   1. Endpoint URI 解析

  解析SCA服务中的URI的规则已经制定好了,URI是如下形式:

  1). endpoint里的URIs或由wsa:EndpointReference的wsa:Address元素指定的URI

  2). 在binding.ws元素中使用“uri”属性显示指定

  3). 由组装规范(Assembly specification)定义的隐式URI。

  2. SCA服务的WSDL描述

  任何一个拥有1个或多个使用HTTP的web 服务绑定的服务必须返回一个WSDL描述,通过在HTTP endpoint后加上一个“?wsdl”的一个http get请求后缀就可以得到。

  下面是一个使用CXF框架生成WSDL描述的的helloworld例子:

  1.定义接口

   @WebService 
  public interface HelloWorld {  
      String sayHi(@WebParam(name="text") String text);  
  }

  2.实现接口

  @WebService(endpointInterface = "com.zx.cxf.service.HelloWorld", serviceName = "HelloWorld")
  public class HelloWorldImpl implements HelloWorld {

   public String sayHi(String text) {
    return "Hello " + text;
   }
  }

  3.配置并发布服务

   <jaxws:endpoint id="helloWorld"
    implementor="com.zx.cxf.service.HelloWorldImpl"
    address="/HelloWorld">
   </jaxws:endpoint>

   4.查看WSDL描述

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

  - <wsdl:definitions name="HelloWorld"   targetNamespace="http://service.cxf.zx.com/"   xmlns:ns1="http://cxf.apache.org/bindings/xformat"   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"   xmlns:tns="http://service.cxf.zx.com/"   xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  - <wsdl:types>
  - <xs:schema attributeFormDefault="unqualified"   elementFormDefault="unqualified"   targetNamespace="http://service.cxf.zx.com/"   xmlns:tns="http://service.cxf.zx.com/"   xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="sayHi" type="tns:sayHi" />
    <xs:element name="sayHiResponse" type="tns:sayHiResponse" />
  - <xs:complexType name="sayHi">
  - <xs:sequence>
    <xs:element minOccurs="0" name="text" type="xs:string" />
    </xs:sequence>
    </xs:complexType>
  - <xs:complexType name="sayHiResponse">
  - <xs:sequence>
    <xs:element minOccurs="0" name="return" type="xs:string" />
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    </wsdl:types>
  - <wsdl:message name="sayHiResponse">
    <wsdl:part element="tns:sayHiResponse" name="parameters" />
    </wsdl:message>
  - <wsdl:message name="sayHi">
    <wsdl:part element="tns:sayHi" name="parameters" />
    </wsdl:message>
  - <wsdl:portType name="HelloWorld">
  - <wsdl:operation name="sayHi">
    <wsdl:input message="tns:sayHi" name="sayHi" />
    <wsdl:output message="tns:sayHiResponse" name="sayHiResponse" />
    </wsdl:operation>
    </wsdl:portType>
  - <wsdl:binding name="HelloWorldSoapBinding" type="tns:HelloWorld">
    <soap:binding style="document"   transport="http://schemas.xmlsoap.org/soap/http" />
  - <wsdl:operation name="sayHi">
    <soap:operation soapAction="" style="document" />
  - <wsdl:input name="sayHi">
    <soap:body use="literal" />
    </wsdl:input>
  - <wsdl:output name="sayHiResponse">
    <soap:body use="literal" />
    </wsdl:output>
    </wsdl:operation>
    </wsdl:binding>
  - <wsdl:service name="HelloWorld">
  - <wsdl:port binding="tns:HelloWorldSoapBinding"   name="HelloWorldImplPort">
    <soap:address location="http://localhost:8081/CxfServiceTest/HelloWorld" />
    </wsdl:port>
    </wsdl:service>
    </wsdl:definitions>

  5. 客户端访问

   public static void main(String args[]) throws Exception {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.getInInterceptors().add(new LoggingInInterceptor());
    factory.getOutInterceptors().add(new LoggingOutInterceptor());
    factory.setServiceClass(HelloWorld.class);
    factory
      .setAddress("http://localhost:8080/CxfService/HelloWorld");
    HelloWorld client = (HelloWorld) factory.create();

    String reply = client.sayHi("HI");
    System.out.println("Server said: " + reply);
   }

  原文出处:http://gocom.primeton.com/blog12255_35328.htm

来源:goCom构客网    作者:liang_ma    
相关的专家答疑
相关的白皮书
过去我曾经对SOA的思想写的挺明白,但估计文章太罗嗦,N多人没看下去。今天和胡争辉在网上聊,他在他的blog上转载了许多关于SOA的文章,他也问了我一些问题……
日前,中国电子技术标准化研究所(CESI)宣布,旨在推进我国SOA标准制定与实施的“SOA标准化国际论坛”将于11月5日至6日在北京举办……
Apache软件基金会最新顶级项目-Apache Tuscany今日宣布发布其Java服务组件架构的1.3.2版本。这是该项目自四个月前脱离ASF孵化器的最新发布……
在SCA规范中提供了关于安全的一套FrameWork,对服务调用过程中的数据传递进行了约束。下面针对其中的WebService Policy,结合自己的实践,对其实现方式进行详解……
服务组件体系结构(Service Component Architecture,SCA)是下一代编程模型,此编程模型提供了三种异步调用模式。您可以使用那些模式异步地调用目标SCA服务……
虚拟化和SOA之间是一种间接的、相辅相成的关系。也许在IT及业务转型中,两者的结合使用会发挥最大的优势。虚拟化有助于更快地显示部署基础设施的投资回报率(ROI)。
云计算的概念越来越流行,Amazon、Google和IBM是第一批将云计算引入公众视线的公司。云计算就是新的Web2.0,一种既有技术上的市场绽放。
安全对于许多的IT部门来说都是一个重要的问题之一,但是SOA安全问题完全是在另一个新的纬度上了。对于SOA为一个机构所带来的许多的好处,例如具有在许多不同的提供者和供应商的情况下混合和匹配服务。
最新更新
专家答疑
技巧
Ron Schmelzer,Jason Bloomberg
你认为通过遵循IT组织步骤可以演变为SOA吗?ZapThink公司明确SOA实行肯定是一个挑战——也不应被视为这一倡议应得到执行的一个步骤就是整个企业的基础……
Dana Gardner
您能解释什么是“私有云”吗,能否举例说明?这是供应商需要建立的基础吗?作为托管服务供应商和服务供应商寻求最有效和最强大的基础设施,作为他们的“云”支持能力……
Andrew Pollack
我们正在寻找一种从主机选择SOAP服务器的请求。我们希望制造一个远程程序呼叫(RPC)从CICS程序的SOAP服务器,其中进程请求,使错误或成功后的反应……