CXF完整实现WebService

1.基础的Web Services平台是XML+HTTP


2.平台元素:

 a.SOAP(简单对象访问协议)

 b.UDDI(通用描述、发现及整合)

 c.WSDL(Web Services描述语言)


3.SOAP(Envelop,Header,body,Fault,HTTPBinding)

SOAP 请求:

POST /InStockHTTP/1.1

Host:www.example.org

Content-Type:application/soap+xml; charset=utf-8

Content-Length:nnn

 

<?xmlversion="1.0"?>

<soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope"

soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

  <soap:Bodyxmlns:m="http://www.example.org/stock">

    <m:GetStockPrice>

     <m:StockName>IBM</m:StockName>

    </m:GetStockPrice>

  </soap:Body>

</soap:Envelope>

 

SOAP 响应:

HTTP/1.1 200 OK

Content-Type:application/soap+xml; charset=utf-8

Content-Length:nnn

 

<?xmlversion="1.0"?>

<soap:Envelope

xmlns:soap="http://www.w3.org/2001/12/soap-envelope"

soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

  <soap:Bodyxmlns:m="http://www.example.org/stock">

    <m:GetStockPriceResponse>

      <m:Price>34.5</m:Price>

    </m:GetStockPriceResponse>

  </soap:Body>

</soap:Envelope>

 

4.WSDL

      元素                 定义

<portType>   web service 执行的操作

<message>   web service 使用的消息

<types>  web service 使用的数据类型

<binding>     web service 使用的通信协议

 

WSDL 绑定可为 web service 定义消息格式和协议细节。

绑定到 SOAP

一个 请求 - 响应 操作的例子:

 

<messagename="getTermRequest">

   <part name="term"type="xs:string" />

</message>

 

<messagename="getTermResponse">

   <part name="value"type="xs:string" />

</message>

 

<portTypename="glossaryTerms">

  <operation name="getTerm">

      <inputmessage="getTermRequest" />

      <outputmessage="getTermResponse" />

  </operation>

</portType>

 

<bindingtype="glossaryTerms" name="b1">

<soap:bindingstyle="document"

transport="http://schemas.xmlsoap.org/soap/http"/>

  <operation>

    <soap:operation

    soapAction="http://example.com/getTerm" />

    <input>

      <soap:body use="literal"/>

    </input>

    <output>

      <soap:body use="literal"/>

    </output>

  </operation>

</binding>

 

binding 元素有两个属性 - name 属性和 type 属性。

name 属性定义 binding 的名称,而 type 属性指向用于 binding 的端口,在这个例子中是 "glossaryTerms" 端口。

soap:binding 元素有两个属性 - style 属性和 transport 属性。

style 属性可取值 "rpc" 或 "document"。在这个例子中我们使用 document。transport 属性定义了要使用的 SOAP 协议。在这个例子中我们使用 HTTP。

operation 元素定义了每个端口提供的操作符。

对于每个操作,相应的 SOAP 行为都需要被定义。同时您必须如何对输入和输出进行编码。在这个例子中我们使用了 "literal"。

 

5.UDDI

UDDI 是一种目录服务,企业可以使用它对 Web services 进行注册和搜索。

UDDI,英文为 "Universal Description, Discovery andIntegration",可译为“通用描述、发现与集成服务”。

 

6.开发应用

标准规范:前期jax-rpc,现在jax-ws

目前主流开发webservice的框架有:axis,xfire,axis2,cxf,关于他们的区别,可以去网上找资料,在此处例子中使用cxf

 

7.案例(cxf实现webservice)

案例:由于无法上传案例,故上传到csdn资源站供大家下载。地址:http://download.csdn.net/detail/mickey_gua/5295927

步骤1:写service(服务端),需要有cxf的相应包,去apache官网下载,写完再测试验证

步骤2:cmd-》cd到cxf的bin目录下,使用命令生成客户端

命令:wsdl2java -p client -d D:\dingzai\dingzaiworksapce\CxfClient\src -client-frontend jaxws21 http://localhost/hello?wsdl

步骤三:在Port_Client中验证。

注意:步骤2和步骤3服务端必须处于运行中。其实服务端只起到了生成wsdl文件的作用。如果有wsdl文件,可以直接生成服务端和客户端。

             本例相对比较简单,要想深入了解webservice的原理推荐自己用jax-ws实现,或不使用代码生成,手动写好客户端。

    步骤2中用wsdl生成java,亦可以使用命令生成其他格式,如js,xml,corba等。

    关于与spring结合的实现方式,请去网上查询,这里不做实现。

问题解决:http://blog.sina.com.cn/s/blog_a53901340101cnt5.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值