私は現在、HttpClientを使用してApacheCouchDBデータベースと対話するコンソールアプリを使用しています。私はこの記事を使用しています:http ://www.asp.net/web-api/overview/web-api-clients/calling-a-web-api-from-a-net-client
PostAsJsonSyncを介してドキュメントをシリアル化してデータベースに送信するときに、クラスのnullプロパティを無視したいのですが、方法がわかりません。
public static HttpResponseMessage InsertDocument(object doc, string name, string db)
{
HttpResponseMessage result;
if (String.IsNullOrWhiteSpace(name)) result = clientSetup().PostAsJsonAsync(db, doc).Result;
else result = clientSetup().PutAsJsonAsync(db + String.Format("/{0}", name), doc).Result;
return result;
}
static HttpClient clientSetup()
{
HttpClientHandler handler = new HttpClientHandler();
handler.Credentials = new NetworkCredential("**************", "**************");
HttpClient client = new HttpClient(handler);
client.BaseAddress = new Uri("*********************");
//needed as otherwise returns plain text
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return client;
}
これが私がシリアル化しているクラスです...
class TestDocument
{
public string Schema { get; set; }
public long Timestamp { get; set; }
public int Count { get; set; }
public string _rev { get; set; }
public string _id { get; set; } - would like this to be ignored if null
}
どんな助けでも大歓迎です。