使用Connect接收事件通知时出错

时间:2017-05-09 10:50:26

标签: c# asp.net-web-api docusignapi

我刚开始使用DocuSign API和Connect,并发布了一个Webhook来接收事件通知。但是,我在管理门户中的“连接失败”列表中收到404未找到错误。这是我的API方法的原理: http://documentsigningapi.networxsolutions.co.uk/Webhook/DocumentSigned 我已在配置设置中的“发布URL”选项中进行了设置。

以下是代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Xml;

namespace DocumentSigningAPI.Controllers
{
    public class WebhookController : ApiController
    {       
        public void DocumentSigned(HttpRequestMessage request)
        {            
            var xmldoc = new XmlDocument();
            var result = request.Content.ReadAsStreamAsync().Result;
            xmldoc.Load(result);           
            var mgr = new XmlNamespaceManager(xmldoc.NameTable);
            mgr.AddNamespace("a", "http://www.docusign.net/API/3.0");
            XmlNode envelopeStatus = xmldoc.SelectSingleNode("//a:EnvelopeStatus", mgr);
            XmlNode envelopeId = envelopeStatus.SelectSingleNode("//a:EnvelopeID", mgr);
            XmlNode status = envelopeStatus.SelectSingleNode("//a:Status", mgr);
            if (envelopeId != null)
            {
                System.IO.File.WriteAllText("C:/inetpub/DocumentSigningDemo/Documents/" +
                    envelopeId.InnerText + "_" + status.InnerText + "_" + Guid.NewGuid() + ".xml", xmldoc.OuterXml);
            }
            if (status.InnerText == "Completed")
            {
                // Loop through the DocumentPDFs element, storing each document.
                XmlNode docs = xmldoc.SelectSingleNode("//a:DocumentPDFs", mgr);
                foreach (XmlNode doc in docs.ChildNodes)
                {
                    string documentName = doc.ChildNodes[0].InnerText; // pdf.SelectSingleNode("//a:Name", mgr).InnerText;
                    string documentId = doc.ChildNodes[2].InnerText; // pdf.SelectSingleNode("//a:DocumentID", mgr).InnerText;
                    string byteStr = doc.ChildNodes[1].InnerText; // pdf.SelectSingleNode("//a:PDFBytes", mgr).InnerText;
                    System.IO.File.WriteAllText("C:/inetpub/DocumentSigningDemo/Documents/" + envelopeId.InnerText + "_" + documentId + "_" + documentName, byteStr);
                }
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

似乎找不到API控制器,所以我现在将我的功能放入一个Web应用程序而不是一个API,现在正在运行。