WebService CXF SOAP基本结构
SOAP 1.1 被提交到 W3CJava代码?
- <?xml?version="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:Header>?????
- ??...?????
- ??...?????
- </soap:Header>?????
- ????
- <soap:Body>?????
- ??...?????
- ??...?????
- ??<soap:Fault>?????
- ????...?????
- ????...?????
- ??</soap:Fault>?????
- </soap:Body>?????
- ????
- </soap:Envelope>????
- ??
- <?xml?version="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:Header>??
- ??...??
- ??...??
- </soap:Header>??
- ??
- <soap:Body>??
- ??...??
- ??...??
- ??<soap:Fault>??
- ????...??
- ????...??
- ??</soap:Fault>??
- </soap:Body>??
- ??
- </soap:Envelope>??
SOAP Envelope 元素Java代码?

- <?xml?version="1.0"?>?????
- <soap:Envelope?????
- xmlns:soap="http://www.w3.org/2001/12/soap-envelope"????
- soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">?????
- ??...?????
- ??Message?information?goes?here?????
- ??...?????
- </soap:Envelope>????
- ??
- <?xml?version="1.0"?>??
- <soap:Envelope??
- xmlns:soap="http://www.w3.org/2001/12/soap-envelope"??
- soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">??
- ??...??
- ??Message?information?goes?here??
- ??...??
- </soap:Envelope>??
xmlns:soap 命名空间Java代码?

- soap:encodingStyle="URI"??

- <?xml?version="1.0"?>?????
- <soap:Envelope?????
- xmlns:soap="http://www.w3.org/2001/12/soap-envelope"????
- soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">?????
- ...?????
- Message?information?goes?here?????
- ...?????
- </soap:Envelope>????
- ??
- <?xml?version="1.0"?>??
- <soap:Envelope??
- xmlns:soap="http://www.w3.org/2001/12/soap-envelope"??
- soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">??
- ...??
- Message?information?goes?here??
- ...??
- </soap:Envelope>??
SOAP Header 元素Java代码?

- <?xml?version="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:Header>?????
- <m:Trans?????
- xmlns:m="http://www.w3school.com.cn/transaction/"????
- soap:mustUnderstand="1">234</m:Trans>?????
- </soap:Header>?????
- ????
- ...?????
- ...?????
- ????
- </soap:Envelope>????
- ??
- <?xml?version="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:Header>??
- <m:Trans??
- xmlns:m="http://www.w3school.com.cn/transaction/"??
- soap:mustUnderstand="1">234</m:Trans>??
- </soap:Header>??
- ??
- ...??
- ...??
- ??
- </soap:Envelope>??
??? 上面的例子包含了一个带有一个 "Trans" 元素的头部,它的值是 234,此元素的 "mustUnderstand" 属性的值是 "1"。Java代码?

- soap:actor="URI"???

- <?xml?version="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:Header>?????
- <m:Trans?????
- xmlns:m="http://www.w3school.com.cn/transaction/"????
- soap:actor="http://www.w3school.com.cn/appml/">?????
- 234????
- </m:Trans>?????
- </soap:Header>?????
- ????
- ...?????
- ...?????
- ????
- </soap:Envelope>????
- ??
- <?xml?version="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:Header>??
- <m:Trans??
- xmlns:m="http://www.w3school.com.cn/transaction/"??
- soap:actor="http://www.w3school.com.cn/appml/">??
- 234??
- </m:Trans>??
- </soap:Header>??
- ??
- ...??
- ...??
- ??
- </soap:Envelope>??
mustUnderstand 属性Java代码?

- soap:mustUnderstand="0|1"???
soap:mustUnderstand="0|1"Java代码?

- <?xml?version="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:Header>?????
- <m:Trans?????
- xmlns:m="http://www.w3school.com.cn/transaction/"????
- soap:mustUnderstand="1">?????
- 234????
- </m:Trans>?????
- </soap:Header>?????
- ????
- ...?????
- ...?????
- ????
- </soap:Envelope>????
- ??
- <?xml?version="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:Header>??
- <m:Trans??
- xmlns:m="http://www.w3school.com.cn/transaction/"??
- soap:mustUnderstand="1">??
- 234??
- </m:Trans>??
- </soap:Header>??
- ??
- ...??
- ...??
- ??
- </soap:Envelope>??
encodingStyle 属性Java代码?

- <?xml?version="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:Body>?????
- ???<m:GetPrice?xmlns:m="http://www.w3school.com.cn/prices">?????
- ??????<m:Item>Apples</m:Item>?????
- ???</m:GetPrice>?????
- </soap:Body>?????
- ????
- </soap:Envelope>????
- ??
- <?xml?version="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:Body>??
- ???<m:GetPrice?xmlns:m="http://www.w3school.com.cn/prices">??
- ??????<m:Item>Apples</m:Item>??
- ???</m:GetPrice>??
- </soap:Body>??
- ??
- </soap:Envelope>??
?? 上面的例子请求苹果的价格。请注意,上面的 m:GetPrice 和 Item 元素是应用程序专用的元素。它们并不是 SOAP 标准的一部分。Java代码?

- <?xml?version="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:Body>?????
- ???<m:GetPriceResponse?xmlns:m="http://www.w3school.com.cn/prices">?????
- ??????<m:Price>1.90</m:Price>?????
- ???</m:GetPriceResponse>?????
- </soap:Body>?????
- ????
- </soap:Envelope>????
- ??
- <?xml?version="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:Body>??
- ???<m:GetPriceResponse?xmlns:m="http://www.w3school.com.cn/prices">??
- ??????<m:Price>1.90</m:Price>??
- ???</m:GetPriceResponse>??
- </soap:Body>??
- ??
- </soap:Envelope>??
SOAP Fault 元素子元素????????描述???????????<faultcode>?供识别故障的代码<faultstring>可供人阅读的有关故障的说明<faultactor>有关是谁引发故障的信息????<detail>????存留涉及 Body 元素的应用程序专用错误信息
SOAP Fault Codes错误?描述?VersionMismatchSOAP Envelope 元素的无效命名空间被发现MustUnderstandHeader 元素的一个直接子元素(带有设置为 "1" 的mustUnderstand 属性)无法被理解。Client?消息被不正确地构成,或包含了不正确的信息。?Server?服务器有问题,因此无法处理进行下去。?
HTTP 协议Java代码?

- POST?/item?HTTP/1.1????
- Host:?189.123.345.239????
- Content-Type:?text/plain?????
- Content-Length:?200????
- ??
- POST?/item?HTTP/1.1??
- Host:?189.123.345.239??
- Content-Type:?text/plain??
- Content-Length:?200??

- 200?OK?????
- Content-Type:?text/plain?????
- Content-Length:?200????
- ??
- 200?OK??
- Content-Type:?text/plain??
- Content-Length:?200??
? 在上面的例子中,服务器返回了一个 200 的状态代码。这是 HTTP 的标准成功代码。Java代码?

- 400?Bad?Request?????
- Content-Length:?0????
- ??
- 400?Bad?Request??
- Content-Length:?0??
SOAP HTTP BindingJava代码?

- Content-Type:?MIMEType;?charset=character-encoding?????
Content-Type: MIMEType; charset=character-encodingJava代码?

- POST?/item?HTTP/1.1????
- Content-Type:?application/soap+xml;?charset=utf-8????
- ??
- POST?/item?HTTP/1.1??
- Content-Type:?application/soap+xml;?charset=utf-8??
Content-LengthJava代码?

- Content-Length:?bytes???
Content-Length: bytesJava代码?

- POST?/item?HTTP/1.1????
- Content-Type:?application/soap+xml;?charset=utf-8????
- Content-Length:?250????
POST /item HTTP/1.1Java代码?

- POST?/InStock?HTTP/1.1????
- Host:?www.example.org?????
- Content-Type:?application/soap+xml;?charset=utf-8????
- Content-Length:?nnn?????
- ????
- <?xml?version="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:Body?xmlns:m="http://www.example.org/stock">?????
- ????<m:GetStockPrice>?????
- ??????<m:StockName>IBM</m:StockName>?????
- ????</m:GetStockPrice>?????
- ??</soap:Body>?????
- ???????
- </soap:Envelope>????
- ??
- POST?/InStock?HTTP/1.1??
- Host:?www.example.org??
- Content-Type:?application/soap+xml;?charset=utf-8??
- Content-Length:?nnn??
- ??
- <?xml?version="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:Body?xmlns:m="http://www.example.org/stock">??
- ????<m:GetStockPrice>??
- ??????<m:StockName>IBM</m:StockName>??
- ????</m:GetStockPrice>??
- ??</soap:Body>??
- ????
- </soap:Envelope>??
SOAP 响应:Java代码?

- HTTP/1.1?200?OK?????
- Content-Type:?application/soap+xml;?charset=utf-8????
- Content-Length:?nnn?????
- ????
- <?xml?version="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:Body?xmlns:m="http://www.example.org/stock">?????
- ????<m:GetStockPriceResponse>?????
- ??????<m:Price>34.5</m:Price>?????
- ????</m:GetStockPriceResponse>?????
- ??</soap:Body>?????
- ???????
- </soap:Envelope>????
原文:http://yakar.iteye.com/blog/968930