Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET Web API多条post消息单个控制器或操作_C#_Asp.net_Xml_Asp.net Web Api - Fatal编程技术网

C# ASP.NET Web API多条post消息单个控制器或操作

C# ASP.NET Web API多条post消息单个控制器或操作,c#,asp.net,xml,asp.net-web-api,C#,Asp.net,Xml,Asp.net Web Api,因此,我有以下问题: 我们有一个场景,第三方正在向我们的服务器发送post消息,我们对此没有控制权,他们希望将所有内容发送到单个url,因此我们无法对查询参数执行任何操作,因此我的问题是,是否可以用单个操作处理不同的post消息。本质上,post消息的内容将定义所述请求需要发生什么 留言1: <xml> <content1> content </content1> <content2> content </content2&g

因此,我有以下问题:

我们有一个场景,第三方正在向我们的服务器发送post消息,我们对此没有控制权,他们希望将所有内容发送到单个url,因此我们无法对查询参数执行任何操作,因此我的问题是,是否可以用单个操作处理不同的post消息。本质上,post消息的内容将定义所述请求需要发生什么

留言1:

<xml>
    <content1> content </content1>
    <content2> content </content2>
</xml>

内容
内容
留言2:

<xml>
    <content1> content </content1>
    <content3> content </content3>
</xml>

内容
内容
正如您所看到的,一些消息将具有类似的属性

谢谢,这是可能的。 指定操作以具有字符串输入参数。这样,您可以将整个消息作为字符串获取,而不必担心其属性。。。 但是,您需要在控制器中实现逻辑以区分消息

[HttpPost]
public ActionResult MyActionForAllMessages(string message)
{
    //Your logic
}

您可以使用以下签名接受任意XML内容

public HttpResponseMessage Post([FromBody]XElement xmlbody) { 
    // Process the xmlbody 
    return new HttpResponseMessage(HttpStatusCode.Created); 
} 

我有关于这种原始媒体类型处理的更多详细信息。

使用参数绑定技术在一次post调用中发送两条消息难道不可能吗?这里描述的东西?不能使用字符串作为参数类型来执行此操作。请看这里了解原因。