私はwcf rest service(4.0)への投稿要求をする必要があります。このサービスは、クライアント側のアプリケーション(jquery)とサーバー側のアプリケーション(asp.netなど)の両方から呼び出されます。 サービスは永続ストアを公開し、CRUD操作を提供します。シリアライゼーションの問題辞書<string、object> - 代替デザインオプション?
私はserialzationに問題があります。
私は数本に関連した記事読んで - WCFを消費する>http://blogs.msdn.com/b/youssefm/archive/2009/04/21/understanding-known-types.aspx
public class CustomType
{
public Dictionary<string,object> CustomObjectCollection {get; set;}
public SavedBy {get; set;}
public SavedOn {get; set;}
public CustomType()
{
CustomObjectCollection = new Dictionary<string,object>();
}
}
public class State1
{
public prop1 {get; set;}
public prop2 {get; set;}
}
public class State2
{
public prop1 {get; set;}
public prop2 {get; set;}
}
クライアント:私は使用できないことがあり
public bool Save(CustomType req)
{
/////////
}
:
public void save()
{
CustomType req = new CustomType();
req.CustomObjectCollection("State1", new State1() {prop1 = val1, prop2 = val2 });
req.CustomObjectCollection("State2", new State2() {prop1 = val3, prop2 = val4 });
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(CustomType));
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, setting);
string json = Encoding.Default.GetString(ms.ToArray());
ms.Close();
Utility.HTTPRequest("http://localhost:2222/MyWCFRestSVC/save", "post", json);
}
WCFメソッドをこの既知のタイプは、このサービスを使用するすべてのクライアントが独自のcuを使用するため回避しますストームの種類。理想的には、サービスは、クライアントが保持したいタイプについて心配すべきではありません。このサービスは、汎用の状態情報だけを保持する永続ストアを公開していることに注意してください。
私はjson文字列表現os State1 & State2を値として格納する辞書の代わりにDictionaryを試しました。私が遭遇した問題は、DataContractJsonSerializerを使用してCustomTypeインスタンスをシリアライズすると、State1のjson文字列& State2は二重シリアル化のためにバックスラッシュ(エスケープ文字)が埋め込まれていると思いますか?
私はDataContractJsonSerializerの代わりにカスタムシリアル化について考えました。
あなたの考えを教えてください。
お時間をいただきありがとうございます。
ありがとうございました。私はその辞書とは関係ないと思う。私はこのプロパティを持っていても、 'public object State {get; set;} '型を知らないので、Stateプロパティを設定するためにState1型を使用すると、'既知型 'を指定せずにDataContractJsonSerializerを使用することはできませんシリアル化する情報。何かご意見は ? – StudentForever