C# 从HTTP Post C捕获XML

C# 从HTTP Post C捕获XML,c#,asp.net-mvc,api,asp.net-web-api,http-post,C#,Asp.net Mvc,Api,Asp.net Web Api,Http Post,因此,我开始研究DocuSign的webhooks实现。我需要从HTTP postdocusign连接接受Web APIC中的XML,然后将该数据发送到SQL Server。主要问题是XML有许多子项,我不知道如何将其映射到模型。我一直在孜孜不倦地寻找一种解决方案,在Post控制器中接受XML,然后将其发送到SQL表,但没有找到任何有效的方法。任何指导都将不胜感激 下面是XML的一个示例 <DocuSignEnvelopeInformation> <EnvelopeStatus

因此,我开始研究DocuSign的webhooks实现。我需要从HTTP postdocusign连接接受Web APIC中的XML,然后将该数据发送到SQL Server。主要问题是XML有许多子项,我不知道如何将其映射到模型。我一直在孜孜不倦地寻找一种解决方案,在Post控制器中接受XML,然后将其发送到SQL表,但没有找到任何有效的方法。任何指导都将不胜感激

下面是XML的一个示例

<DocuSignEnvelopeInformation>
<EnvelopeStatus>
<RecipientStatuses>
<RecipientStatus>
<Type>Signer</Type>
<Email>user@user.com</Email>
<UserName>test user</UserName>
<RoutingOrder>1</RoutingOrder>
<Sent>2018-03-05T10:44:06.443</Sent>
<Delivered>2018-03-05T10:45:22.443</Delivered>
<Signed>2018-03-05T10:45:24.413</Signed>
<DeclineReason/>
<Status>Completed</Status>
<RecipientIPAddress>00.00.00.00</RecipientIPAddress>
<RecipientId>aa923fgf2-e59d-45df-8447-8e55437b6cf7</RecipientId>
</RecipientStatus>
</RecipientStatuses>
<TimeGenerated>2018-03-05T10:45:42.6635679</TimeGenerated>
<EnvelopeID>3034gfdfd3-e6c3-4dsg6-af18-252f8fdsf3b5</EnvelopeID>
<Subject>Testing Webhooks DocuSign</Subject>
<Created>2018-03-05T10:42:59.24</Created>
<Sent>2018-03-05T10:45:25.617</Sent>
</EnvelopeStatus>
</DocuSignEnvelopeInformation>

using System.Web.Http;

namespace DocuSignAPI.Controllers
{
    public class DocuSignEnvelopeController : ApiController
    {
        [HttpPost]
        public void Post([FromBody]  Models.EnvelopeStatus envelope, Models.RecipientStatus status, Models.RecipientStatuses statuses, Models.DocuSignEnvelopeInformation info)
        {


        }
    }
}

从中生成模型类 然后你可以继续你的道路

DocuSignEnvelopeInformation是您的根对象,所有传入的数据都将包装在签出代码中

namespace DocuSignAPI.Controllers
{
    public class DocuSignEnvelopeController : ApiController
    {
        [HttpPost]
        public void Post(Models.DocuSignEnvelopeInformation data)
        {

        }
    }
}

我假设您不想把它放在数据库的xml数据类型列中?如果您想要一个模型,请复制xml,在一个空白的类文件中转到Visual Studio,然后选择“编辑”、“粘贴特殊”、“将xml粘贴为类”,然后清理它设置的空洞数据类型。谢谢,我确实尝试过,您是对的,需要进行大量清理,所以我现在拥有了该模型,这要归功于那个很棒的模型生成器。然后,我会像上面的代码那样在Post方法中为每个类声明多个参数吗?@FrankCastle616希望更新的答案会对您有所帮助。好的,这更有意义。我承诺的最后一个问题是,控制器如何处理XML,例如读取XML并将其发送到DB。再次为自己是C而感到抱歉noob@FrankCastle616这是一个宽泛的问题,但我会很快回答它,假设您在sql数据库中有5列,在模型中有5个属性,所以您将在该sql表的查询中写入insert,并在param中传递模型的属性。希望这有意义。我撒谎了,不是我的最后一个问题lol。是的,我理解你的评论,我想我的问题更多地集中在如何获取每个XML节点流读取器的值上?并将其指定给正确的模型属性?