2016-01-28 24 views
2

我有以下的MVC 5休息控制器:的DocuSign连接监听器MVC5阿比

namespace Rest4.Controllers 
{ 
    public class DocuSignController : ApiController 
    { 
     // POST api/docusign 
     public void Post([FromBody]DocuSignAPI.DocuSignEnvelopeInformation DocuSignEnvelopeInformation) 
     { 
      try 
      { 
       System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(DocuSignAPI.DocuSignEnvelopeInformation)); 
       XmlSerializer serializer = new XmlSerializer(typeof(DocuSignAPI.DocuSignEnvelopeInformation)); 
       StringBuilder sb = new StringBuilder(); 
       using (StringWriter writer = new StringWriter(sb)) 
       { 
        serializer.Serialize(writer, DocuSignEnvelopeInformation); 
       } 
       string fileName = DateTime.Now.Ticks.ToString(); 
       using (StreamWriter outputFile = new StreamWriter(string.Format(@"c:\clientuploads\{0}.xml", fileName))) 
       { 
outputFile.WriteLine(sb.ToString()); 
outputFile.WriteLine("Nothing to see here"); 
} 
      } 
      catch { } 
     } 

然而,当我去的DocuSign连接设置,并尝试发送相同的,我得到的是:

<?xml version="1.0" encoding="utf-16"?> 
<DocuSignEnvelopeInformation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:nil="true" /> 
Nothing to see here 

不过,如果我看的的DocuSign网站日志:

1/28/2016 8:49:56 PM Connect send to: http://somewhere.com/Rest/api/DocuSign 
1/28/2016 8:49:56 PM Envelope Data (documents were included):<?xml version="1.0" encoding="utf-8"?><DocuSignEnvelopeInformation xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.docusign.net/API/3.0"><EnvelopeStatus><RecipientStatuses><RecipientStatus><Type>Signer</Type><Email>someemailaddress</Email><UserName>somebody</UserName><RoutingOrder>1</RoutingOrder><Sent>2016-01-13T10:35:11.16</Sent>....<Sequence>4</Sequence></DocumentStatus></DocumentStatuses></EnvelopeStatus></DocuSignEnvelopeInformation> 

那么,为什么是我从做得到的文件cuSign为空?有更好的方法来捕获信息吗?如果我尝试使用Post([FromBody]string DocuSignEnvelopeInformation),则DocuSign站点上出现500错误

回答

0

您是否在初始化序列化程序时指定了默认名称空间,如下所示。

XmlSerializer serializer = new XmlSerializer(typeof(DocuSignEnvelopeInformation), "http://www.docusign.net/API/3.0"); 
DocuSignEnvelopeInformation envelopeInfo = serializer.Deserialize(reader) as DocuSignEnvelopeInformation; 
+0

一旦您进入方法,对象就已经为空 - 它不会从POST中获取发布的正文。 –

+0

@DainMuller它看起来像WebAPI试图解析模型,然后它将它放到身体上,如果您有'DocuSignEnvelopeInformation'作为参数。而是用'this.Request.Content.ReadAsStreamAsync()。Result'访问请求体,然后像@Malu所说的那样通过解串器来运行它。只需自己做这个。让我知道你是否需要帮助。 – JustMaier