2012-07-26 13 views
4

我在使用webHttpBinding(soap 1.1)的WCF Web服務中收到沒有設置爲對象錯誤實例的對象引用我注意到,如果您有輸入參數某些順序錯誤不會引發。WCF和SOAP Envelope中的輸入參數順序

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:not="http://schemas.globalfoundries.com/NotificationService"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <not:NotifyWorkflowItemUpdate> 
     <not:userIDs>testUserID</not:userIDs> 
     <not:taskID>testTaskID</not:taskID> 
     <not:taskType>testTaskType</not:taskType> 
     <not:status>testStatus</not:status> 
     <not:appID>testAppID</not:appID> 
     <not:message>testMessage</not:message> 
     </not:NotifyWorkflowItemUpdate> 
    </soapenv:Body> 
</soapenv:Envelope> 

但是如果我更改請求模板的輸入參數的順序我得到上述錯誤。即(注意消息和用戶ID參數被切換)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:not="http://schemas.globalfoundries.com/NotificationService"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <not:NotifyWorkflowItemUpdate> 
    <not:message>testMessage</not:message> 
     <not:taskID>testTaskID</not:taskID> 
     <not:taskType>testTaskType</not:taskType> 
     <not:status>testStatus</not:status> 
     <not:appID>testAppID</not:appID> 
     <not:userIDs>testUserID</not:userIDs> 
     </not:NotifyWorkflowItemUpdate> 
    </soapenv:Body> 
</soapenv:Envelope> 

爲什麼會發生這種情況?請求參數是通過順序而不是名稱映射到.Net方法參數的嗎?是否有必須在服務合同上指定一個屬性來使命名參數映射成爲可能?

回答

3

SOAP消息的XML模式指定順序。按照元素事項的XML順序,WCF正在根據模式驗證XML。

+0

有沒有辦法使用類似命名的參數,使消費客戶機可以按任何順序,只要指定了正確的名稱指定參數在標籤中? – Harindaka 2012-07-26 11:51:02

+0

我不這麼認爲。 SOAP和XSD是爲互操作性設計的明確定義的標準。不要認爲SOAP是方法和參數,因爲您的語言會生成代理。認爲它是消息傳遞,並嚴格驗證該消息的合同。 – softveda 2012-07-26 12:24:05

+0

我剛剛發佈了相同的問題,只是我在ASMX中添加了這個順序並不重要。我認爲在WCF中會有一個設置可以讓你模仿ASMX中的無序功能。 – 2013-09-20 20:42:12

相關問題