JSONデータを送受信するRESTベースのWCFサービスを作成して遊んでいます。私はほとんどのことを機能させることができますが、この最後の部分は本当に私を困惑させました.
サービスに複雑なデータ型を送信しています。データを送信していますが、クラスがインスタンス化されていないようです。
クラス宣言 (別のクラス ファイル内):
public class WhereItsAt
{
public float Latitude { get; set; }
public float Longitude { get; set; }
public string Category { get; set; }
public string SearchTerms { get; set; }
public float Distance { get; set; }
}
[WebInvoke(Method = "POST", UriTemplate = "/New", RequestFormat = WebMessageFormat.Json)]
public string Create(WhereItsAt newstuff)
{
return string.Format("Success: {0} <Should show search terms here>", newstuff.SearchTerms);
}
問題は、newstuff.SearchTerms (OK、newstuff のすべて) が null または 0 であることです。
クラスを変更した場合:
public class WhereItsAt
{
public float Latitude { get; set; }
public float Longitude { get; set; }
public string Category { get; set; }
public string SearchTerms { get{return "hello"}; set; }
public float Distance { get; set; }
}
データを返します。
私はフィドラーで電話しています:
POST http://127.0.0.1:8835/testing/New
HTTP/1.1 ユーザー エージェント: Fiddler Host: 127.0.0.1:8835 Content-Length: 122 Content-Type: application/json; 文字セット=utf-8
[{"緯度":43.34,"経度":45.234,"カテゴリー":"未設定","検索条件":"ダウンタウン","距離":12.234}]
クラスがインスタンス化されていないように見えます。セットにダミーコードを作成しました
{set{int i = 1;};
しかし、セットにブレークポイントを作成すると、それが呼び出されることはありません。
私は何を間違っていますか?