webservice

SOAP vs Rest
SOAP 就是传统的webservice, 定义一个wsdl,(或由服务器端代码生成一个wsdl),客户端那到这个wsdl用工具(cxf)就能生成自己的客户端接口一系列代码。 之间传输的内容需要符合wsdl中的schema校验。

Rest 是用url来表明自己要传输的内容,
http://localhost:9000/categoryservice/category/001/books
其格式需要符合
@Path("/category/{id}/books") 的定义
这个和springMVC中的@RequestMapping("/update")很像

两者的对比
soap需要用工具生产一大堆的stub skelton文件 重量级
rest很简洁 轻量级, 不需要额外代码, 而且传输的内容不需要额外的格式

soap 跨系统做的好,只要基于wsdl就ok, 适用于.Net和Java的通讯
rest 我不知道跨语言是怎么用的

一般而言一个提供webservice服务的系统都会提供这两种类型的api, 所以对于使用者是透明的。


------------------------------

types:用来定义访问的类型
message:SOAP
portType:指明服务器的接口,并且通过operation绑定相应的in和out的消息:其中in表示参数,out表示返回值
binding:指定传递消息所使用的格式
service:指定服务所发布的名称

[img]http://dl.iteye.com/upload/attachment/0077/4306/230293aa-9983-3730-8592-4eca08186b0e.jpg[/img]


以上是两种对WSDL的说明
如果用自己的话来讲就是
types 定义的是schema文件或是其内容
message 就是对需要哪些schema中的对象作为SOAP对象的
portType 定义了接口名字和需要发布哪些方法, 该方法的input和output参数是message中定义的类型
binding和service 规定了发布的url地址等信息。属于physical locations, 不需要我们care

Restful可以参照 http://reymont.iteye.com/blog/1523822
附件中是soap实现 和 restful的实现
对于restful实现有两个问题
1, 客户端的PO类即Category, Book 如何生成? 通过浏览器看到的xml? http://localhost:9000/categoryservice/category/001/books
2, 有没有第三方的工具类似于xmlspy的来作为工具,测试restful的?
需要指定访问方法post get delete等 SOAPUI?
firefox带有restClient的插件可以用来测试

[img]http://dl.iteye.com/upload/attachment/0078/4357/55b159f1-05ca-3ded-adb4-4cb69350dd27.jpg[/img]

--
用soapUI测试restful, 可以设置http的method(get post delete等),但是无法模拟对象的实体类, 比如需要新增一个实体类时需要传递一个PO的对象,而在soapUI中无法构造出。
-- 该对象有json格式模拟, 而json格式的说明需要由提供rest的服务端提供
-- 可以通过get方法来得到json格式, 修改后再发送。 firefox 插件支持
见附件 email.rar


<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="HelloWorldImplService" targetNamespace="http://tristan01.com/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://tristan01.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xs:schema elementFormDefault="unqualified" targetNamespace="http://tristan01.com/" version="1.0" xmlns:tns="http://tristan01.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="add" type="tns:add"/>
<xs:element name="addResponse" type="tns:addResponse"/>
<xs:complexType name="add">
<xs:sequence>
<xs:element name="arg0" type="xs:int"/>
<xs:element name="arg1" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addResponse">
<xs:sequence>
<xs:element name="return" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="addResponse">
<wsdl:part element="tns:addResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="add">
<wsdl:part element="tns:add" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="HelloWorld">
<wsdl:operation name="add">
<wsdl:input message="tns:add" name="add">
</wsdl:input>
<wsdl:output message="tns:addResponse" name="addResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldImplServiceSoapBinding" type="tns:HelloWorld">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="add">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="add">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="addResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorldImplService">
<wsdl:port binding="tns:HelloWorldImplServiceSoapBinding" name="HelloWorldImplPort">
<soap:address location="http://localhost:8888/ns"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值