0
我有兩個asp.net mvc應用程序試圖通過發送一個複雜的序列化對象從一個應用程序到彼此進行通信另一個。Asp.net Mvc收到一個複雜的對象作爲鍵/值對數組列表
但是,當數據到達另一端時,該對象作爲鍵值對的數組列表進入。以下是要發送/接收內容的詳細信息。
下面是我用來發送JSON對象
using (var hc = new HttpClient())
{
hc.DefaultRequestHeaders.Accept.Clear();
hc.DefaultRequestHeaders.Accept.Add(Media);
var dict = new Dictionary<string, DejaVuObject> {{"Entity", obj}};
var strinified = JsonConvert.SerializeObject(dict);
var stringContent = new StringContent(strinified, Encoding.UTF8, "application/json");
var response = await hc.PostAsync(url, stringContent);
return response;
}
接收方法簽名的代碼
[HttpPost]
public ActionResult RecieveEntity(Dictionary<string, object> post)
這裏是我送
{
"Main Service ID": "1",
"Node ID": "",
"Parameters": [
{
"Name": "firstname",
"Validation": {
"Entity": 0,
"EntityListFilter": "",
"IsNotEditable": false,
"IsPrimaryIdentifier": false,
"IsRequired": true,
"IsUnique": false,
"Parameter Format": 0,
"ParameterMode": ""
}
}
],
"CustomEvents": [
{
"Description": "event description",
"Message": "new message",
"MilestoneCondition": "milestone information.",
"Name": "new message",
"TheFields": []
}
],
"Processings String": "Action failed.[TN01-31:Action failed]"
}
下面是我收到
{
"Processings String": "Action failed.[TC01-71:Action failed while processing the request.]::Action succeeded.[TC01-54:Processing this command was successful.]",
"Parameters": "[Name, Firstname][Validation, ][Key, 2e431711-2ba9-40ef-985e-dbfa8c13a932][isrequired, True][fieldname, ][Name, Lastname][Validation, ][Key, be4de2d6-d39e-44fa-8f31-b4b0964f82da]",
"CustomEvents": "[Description, Processing this command was successful][Message, Action suceeded][MilestoneCondition, When command processing suceeds.][Name, Action suceeded][TheFields, System.Collections.Generic.List`1[System.Dynamic.DejaVuObject]]",
"Main Service ID": "1"
}
如果你看看正確的東西進入的其它系統,你會發現,大部分的內部對象是鍵/值對的陣列,而不是普通的已發送對象數組。我做錯了什麼,我該如何糾正它?
什麼是接收方法簽名? – Krishna
@krishna查看我的編輯。 – Cizaphil
將字典更改爲動態兩端,如'Dictionary' –
Krishna