我有两个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"
}
如果你正确查看其他系统的内容,你会发现内部对象的大部分是一个键/值对的数组,而不是发送的普通对象数组。我做错了什么,我该如何纠正呢?
答案 0 :(得分:0)
您正在使用字典类型来接收内容。根据您的定义,数据包从app1发送。所以更新app1并不能帮到你。
由于@Krishna建议更新签名以使用动态,或者您可以扩展当前的app2方法来处理新界面。
您是否有一个现有集成应用程序的数据包示例?