2016-04-07 33 views
0

我是WCF的新手,但在閱讀StackOverflow上的文章和幾個問題後,設法啓動了一個自託管的RESTful服務。 我最終面臨的問題是返回到操作合同的參數值爲空。我意識到有關於此的幾個以前的問題,但我認爲我已經照顧了在那裏提出的所有設置,並沒有解決問題。 我能夠得到一個json響應,但是它的json正文被髮送到一個「POST」調用,而不是被反序列化到參數對象中。WCF:在遇到反序列化時遇到「無法識別的元素」

繼承人的代碼: -

[ServiceContract] 
public interface IExchServer 
{ 
    [OperationContract] 
    [WebInvoke(Method = "GET", 
     ResponseFormat = WebMessageFormat.Json, 
     UriTemplate = "/init")] 
    DomainInfo init(); 

    [OperationContract] 
    [WebInvoke(Method = "POST", 
     RequestFormat = WebMessageFormat.Json, 
     ResponseFormat = WebMessageFormat.Json, 
     BodyStyle = WebMessageBodyStyle.Wrapped, 
     UriTemplate = "/close")] 
    string close(DomainInfo connection); } 

這裏是類

[DataContract] 
public class DomainInfo 
{ 

    [DataMember] 
    public string Domain { get; set; } 

    [DataMember] 
    public string UserName { get; set; } 

    [DataMember] 
    public string password {get;set;}} 

而在其他客戶端我使用(郵遞員),我設置了標題爲application/JSON。我曾嘗試用以下的有效載荷:

{"DomainInfo":{ 
"Domain": "domain.com", 
"UserName": "[email protected]", 
"password": "[email protected]"}} 

以及

{"Domain": "domain.com", 
"UserName": "[email protected]", 
"password": "[email protected]"} 

在第一個我得到以下WCF跟蹤

Incoming HTTP request to URI 'http://localhost:9001/ExchServer/close' matched operation 'close' 
Opening System.ServiceModel.InstanceContext/17818390 
Opened System.ServiceModel.InstanceContext/17818390 
A message was read 
An unrecognized element was encountered in the XML during deserialization which was ignored. 

,而在第二個我得到

Incoming HTTP request to URI 'http://localhost:9001/ExchServer/close' matched operation 'close'. 
Opening System.ServiceModel.InstanceContext/5923895 
Opening System.ServiceModel.InstanceContext/5923895 
A message was read 
An unrecognized element was encountered in the XML during deserialization which was ignored 
An unrecognized element was encountered in the XML during deserialization which was ignored 
An unrecognized element was encountered in the XML during deserialization which was ignored 

有沒有其他錯誤報告。在調試模式下啓動VS,我看到該參數爲空。請引導我,因爲它似乎是一個非常基本的用法。 init()協議按預期工作,並返回一個json字符串。 在此先感謝。

回答

相關問題