【发布时间】:2019-12-20 20:35:13
【问题描述】:
我目前正在向现有 WCF 服务添加一个新端点,以接收来自 DocuSign 的 web-hook 通知。
该方法需要一个类型为 DocuSignEnvelopeInformation 的单个参数,该参数是我添加为服务参考的 DocuSign API 中定义的一个类。
来自 DocuSign 的 XML 请求使用命名空间“http://www.docusign.net/API/3.0”。
实现非常简单。
界面:
[ServiceContract(Namespace = "http://www.docusign.net/API/3.0")]
public interface IDocuSignEventListener
{
[OperationContract]
[XmlSerializerFormat]
string DocuSignConnectUpdate(DocuSignEnvelopeInformation DocuSignEnvelopeInformation);
}
控制器:
[ServiceBehavior(Namespace = "http://www.docusign.net/API/3.0")]
public class DocuSignEventService : IDocuSignEventListener
{
[OperationBehavior]
public string DocuSignConnectUpdate(DocuSignEnvelopeInformation DocuSignEnvelopeInformation)
{
// process the notification
return DocuSignEnvelopeInformation.EnvelopeStatus.EnvelopeID;
}
}
当我运行服务并访问端点的帮助页面时,我看到以下请求是预期的:
如您所见,命名空间属性不在根节点上。
但是,DocuSign 正在发送以下 XML,其命名空间位于根节点上:
服务为此请求返回 400 错误,但有以下异常:
Unable to deserialize XML body with root name 'DocuSignEnvelopeInformation'
and root namespace 'http://www.docusign.net/API/3.0' (for operation
'DocuSignConnectUpdate' and contract ('IDocuSignEventListener', 'http://www.docusign.net/API/3.0'))
using XmlSerializer. Ensure that the type corresponding to the XML is added to the known types collection
of the service.
如果我手动编辑请求正文并将命名空间移动到 EnvelopeStatus 节点,则一切正常,但显然我无法控制生产中请求的格式。
我无法弄清楚为什么服务需要内部节点上的命名空间声明,特别是考虑到 DocuSignEnvelopeInformation 对象是直接从 DocuSign API 引用的。
非常感谢任何指导。
【问题讨论】:
标签: xml rest wcf docusignapi