传递多个参数以在DocuSign <returnurl> XML标记</returnurl>中返回MVC中的个性化页面

时间:2013-10-24 21:01:13

标签: c# xml asp.net-mvc docusignapi

我正在使用DocuSign REST API在C#MVC应用程序中集成协议签名。我已经获得了几乎所有的功能,但是我在DocuSign iframe签名完成后加载的页面遇到了一些问题。我在模板身份验证之外的项目中创建了一个视图,并将XML“returnUrl”标记指向它。

它现在加载该页面,但问题来自于尝试传递多个参数。理想情况下,当我尝试在URL中包含所有3个查询字符串参数时,我想传入3个不同的字符串但XML请求错误。有一个它完成得很好。

当前代码没有输出错误并允许签名过程在将单个参数传递到签名后页面时完成:

string reqBody = "<recipientViewRequest xmlns=\"http://www.docusign.com/restapi\">" +
                "<authenticationMethod>email</authenticationMethod>" +
                    "<email>" + model.TSM.Email + "</email>" +      // NOTE: Use different email address if username provided in non-email format!
                    "<returnUrl>https://maaxspasportal.com/TerritorySalesManagement/AfterSigningLandingPage?contactName=" + model.ContactName.Replace(" ", "%20") + "</returnUrl>" +  // username can be in email format or an actual ID string
                    "<clientUserId>1</clientUserId>" +
                    "<userName>" + model.TSM.Name + "</userName>" +
                    "</recipientViewRequest>";

使XML请求无效的代码返回错误:

            string contactName = model.ContactName.Replace(" ", "%20");
            string companyName = model.CompanyName.Replace(" ", "%20");
            string contactEmail = model.Dealer.Email.Replace(" ", "%20");

            string reqBody = "<recipientViewRequest xmlns=\"http://www.docusign.com/restapi\">" +
                "<authenticationMethod>email</authenticationMethod>" +
                    "<email>" + model.TSM.Email + "</email>" +      // NOTE: Use different email address if username provided in non-email format!
                    "<returnUrl>https://maaxspasportal.com/TerritorySalesManagement/AfterSigningLandingPage?contactName=" + contactName + "&companyName=" + companyName + "&contactEmail=" + contactEmail + "</returnUrl>" +  // username can be in email format or an actual ID string
                    "<clientUserId>1</clientUserId>" +
                    "<userName>" + model.TSM.Name + "</userName>" +
                    "</recipientViewRequest>";

以下是我收到的错误:

<errorDetails xmlns="http://www.docusign.com/restapi" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><errorCode>INVALID_REQUEST_BODY</errorCode><message>The request body is missing or improperly formatted. An error occurred while parsing EntityName. Line 1, position 271.</message></errorDetails>

有没有人遇到过这个?有没有更好的方法将参数传递给我的“returnUrl”页面?谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

尝试在网址中对&符号(&amp; )进行编码。例如,尝试将 returnUrl 设置为以下内容:

<returnUrl>https://maaxspasportal.com/TerritorySalesManagement/AfterSigningLandingPage?contactName=John%20Smith&#038;companyName=ABC_Company&#038;contactEmail=johnsmith@test.com</returnUrl>

注意我已经用&amp;#038; 替换了每次出现的&amp; 8 和<之间没有空格strong>; )

更新:以下是获取收件人网址的完整XML请求:

POST https://{{env}}.docusign.net/restapi/{{version}}/accounts/{{acctId}}/envelopes/{{envelopeId}}/views/recipient

<recipientViewRequest xmlns="http://www.docusign.com/restapi">
  <authenticationMethod>Email</authenticationMethod>
  <email>johnsmith@test.com</email>  
  <returnUrl>https://maaxspasportal.com/TerritorySalesManagement/AfterSigningLandingPage?contactName=John%20Smith&#038;companyName=ABC_Company&#038;contactEmail=johnsmith@test.com</returnUrl>
  <clientUserId>123</clientUserId>
  <userName>John Smith</userName>
</recipientViewRequest>

返回的响应如下:

<viewUrl 
    xmlns="http://www.docusign.com/restapi" 
    xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <url>https://demo.docusign.net/Member/StartInSession.aspx?t=87aaeca6-77cd-44f5-9ec0-8384270f52e7</url>
</viewUrl>

在新浏览器中,我导航到响应的 url 元素中指定的网址并完成/确认签名。提交信封后,我被重定向到我之前在请求中指定的重定向页面。该页面似乎成功解析了所有3个查询字符串参数:

enter image description here