2016-04-07 3 views
0

WCFを初めて使用しましたが、StackOverflowに関する記事やいくつかの質問を経て、自営のRESTfulサービスを立ち上げました。 私が最終的に直面している問題は、操作コントラクトに返されるパラメータ値がnullであることです。私はこれにいくつかの以前の質問があることを認識しますが、私はそこで育ったすべての設定を世話して、問題を解決していないと思います。 私はjsonレスポンスを得ることができますが、パラメータオブジェクトにデシリアライズされていない "POST"コールに送られるjsonボディが返されます。WCF:デシリアライズ中に「Unrecognized Elementが見つかりました」

相続コード: - ここ

[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;}} 

され、残りのクライアントに私はアプリケーション/ JSONにヘッダを設定している(ポストマン)を使用しています。私は、次のペイロードを試してみました:私は、WCFの下に取得する最初のものでは

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

など

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

秒1で、私は

を取得しながら、

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文字列を返します。 ありがとうございます。

答えて

関連する問題