2017-08-14 55 views
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" 
} 

如果你看看正确的东西进入的其它系统,你会发现,大部分的内部对象是键/值对的阵列,而不是普通的已发送对象数组。我做错了什么,我该如何纠正它?

+1

什么是接收方法签名? – Krishna

+0

@krishna查看我的编辑。 – Cizaphil

+2

将字典更改为动态两端,如'Dictionary ' – Krishna

回答

0

它是您使用字典类型接收内容的事实。在这一点上,数据包是从app1发送的,按照您的定义。所以更新app1不会帮助你。

由于@Krishna建议更新签名以使用动态,或者您可以扩展当前的app2方法来处理新的界面。

您是否有一个来自现有集成应用程序之一的数据包示例?

相关问题