0

我正在尝试测试 REST API 以在 WCF Web 服务中使用 C# 通过模板引用的文档请求签名。

登录的第 1 步有效并返回 accountID 和 baseURl;

步骤 2 失败并显示Bad Request.

这是我的代码:

try {
    ...
    string requestBody = "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" +
            "<accountId>" + accountId + "</accountId>" +
            "<status>" + "sent" + "</status>" +
            "<emailSubject>" + "API Call for Embedded Sending" + "</emailSubject>" +
            "<emailBlurb>" + "This comes from C#" + "</emailBlurb>" +
            "<templateId>" + "9A535489-0FB6-42B2-82C1-A06DA36025B4" + "</templateId>" +
            "<templateRoles>" +                       
            "<email>" + "abc@gmail.com" + "</email>" +  // NOTE: Use different email address if username provided in non-email format!
            "<name>" + "GRAVITY1003" + "</name>" +              // username can be in email format or an actual ID string
            "<roleName>" + "GRAVITY1003" + "</roleName>" +
            "</templateRoles>" +
            "</envelopeDefinition>";

    // append "/envelopes" to baseUrl and use in the request
    request = (HttpWebRequest)WebRequest.Create(baseURL + "/envelopes");
    request.Headers.Add("X-DocuSign-Authentication", authenticateStr);
    request.ContentType = "application/xml";
    request.Accept = "application/xml";
    request.ContentLength = requestBody.Length;
    request.Method = "POST";
    // write the body of the request
    byte[] body = System.Text.Encoding.UTF8.GetBytes(requestBody);
    Stream dataStream = request.GetRequestStream();
    dataStream.Write(body, 0, requestBody.Length);
    dataStream.Close();
    // read the response
    webResponse = (HttpWebResponse)request.GetResponse();------> It fails here
    sr = new StreamReader(webResponse.GetResponseStream());
    responseText = sr.ReadToEnd();
    uri = responseText;
}
catch (WebException e)
{
    using (WebResponse response = e.Response)
    {
        HttpWebResponse httpResponse = (HttpWebResponse)response;
        Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
        using (Stream data = response.GetResponseStream())
        {
            string text = new StreamReader(data).ReadToEnd();
            Console.WriteLine(text);
        }
    }
}

谁能告诉我我做错了什么?我查看了 API 演练并进行了相应的编码。不知道为什么会这样。

4

1 回答 1

0

Looks like there was a bug in the Gist you were working off of, the wrong version was mistakenly uploaded. The Gist has been fixed, the issue was just one xml node that was missing.

Since you can have multiple template roles on a given template, there needs to be an extra xml node that separates each role. What you need to do is add singular <templateRole></templateRole> xml nodes in between the <templateRoles></templateRoles> nodes.

So your request body should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<envelopeDefinition xmlns="http://www.docusign.com/restapi">
   <accountId>123456</accountId>
   <status>sent</status>
   <emailSubject>API Call for sending signature request from template</emailSubject>
   <emailBlurb>This comes from Java</emailBlurb>
   <templateId>EA64D446-3BFA-*********************</templateId>
   <templateRoles>
      <templateRole>
         <email>recipient_email_address</email>
         <name>recipient_name</name>
         <roleName>template_role_name</roleName>
      </templateRole>
   </templateRoles>
</envelopeDefinition>
于 2013-11-05T20:55:36.703 回答