【发布时间】:2018-03-07 18:15:00
【问题描述】:
所以我开始着手实现 DocuSign 的 webhook。我需要从 HTTP 帖子(docusign 连接)接受 Web API(C#)中的 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)
{
}
}
}
【问题讨论】:
-
我假设你不想把它放在数据库的
xml数据类型列中?如果你想要一个模型,复制 xml,在一个空白类文件中转到 Visual Studio,然后选择编辑,粘贴特殊,将 xml 粘贴为类,然后清理它设置的空洞数据类型。 -
谢谢,我试过了,你说得对,需要大量清理
标签: c# asp.net-mvc api asp.net-web-api http-post