我正在實現一個客戶端Web服務調用到使用.NET實現的SOAP Web服務。
我用WSDL提供的,我很高興與我送,如:爲什麼我無法在SOAP主體中發送純XML?
POST /publicws/query.asmx HTTP/1.1
Host: www.blablabla.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.blablabla.com/WebServices/Query"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Query xmlns="http://www.blablabla.com/WebServices/Query"> <- <Query> tag #1
<string_XML>
<Query> <- <Query> tag #2
<Param1>param1value</Param1>
<Param2>param2value</Param2>
</Query>
</string_XML>
</Query>
</soap:Body>
</soap:Envelope>
但是,我得到一個錯誤響應:
<faultcode>soap:Client</faultcode>
<faultstring>Server was unable to read request. --> There is an error in XML document (6, 2). --> 'Element' is an invalid node type. Line 6, position 2.</faultstring>
然而,通過發送以下信息(HTML的它是成功的:
[...]
<Query xmlns="http://www.blablabla.com/WebServices/Query">
<string_XML>
<Query><Param1>param1value</Param1><Param2>param2value</Param2></Query>
</string_XML>
[...]
請注意,在標籤#2周圍添加CDATA也是成功的。
上述修復對我來說似乎很髒。
我的問題是關於服務器端。
我認爲路由是使用SOAP Action執行的,並且SOAP Body只應包含業務相關數據。
然而,在我來說,這似乎並沒有工作的方式:
-The查詢標籤有兩次(我猜一次太多)
- 和string_XML標籤肯定是不存在的業務
[...]
<Query xmlns="http://www.blablabla.com/WebServices/Query"> <- <Query> tag #1 useless ?
<string_XML> <- useless ?
&Query&... <- <Query> tag #2 should be pure xml ?
[...]
查詢標籤#1和string_XML標籤從業務角度看似乎完全沒有用處。
爲什麼我不能在SOAP Body中發送純XML?
是否有第一個服務在string_XML之前解析請求,然後將內容傳遞給另一段處理業務的代碼?
負責此事的場景背後的架構是什麼?
在此先感謝您的幫助,
尼古拉斯。
感謝您的回覆,我不確定要理解。如果使用SOAP Envelope和SOAP Body,如果這是您的開銷,那麼我很好。但在SOAP Body中,我只想放置業務相關數據,因爲路由是通過http標頭中的SoapAction執行的。什麼樣的體系結構強制SoapBody將業務數據封裝在無用的XML標記中(查詢#1,在我的情況下是string_XML)? – user727504 2011-04-27 16:03:59