我正在使用.NET Web应用程序(Web窗体)。我需要将文档签名体验嵌入到我的Web应用程序中,最好是通过iframe。
是否可以通过Web应用程序对docusign进行身份验证,然后将签名体验带入Iframe?
也可以在签名完成时重定向到自定义网址,拒绝签名,关闭窗口等等。
答案 0 :(得分:2)
这是关于如何在C#中进行嵌入式签名的API演练的副本。您可以在此处找到其他演练:http://iodocs.docusign.com/APIWalkthroughs。
下面的代码应该完全符合您的要求 - 为您提供经过身份验证的IFRAME,以便进行签名。在使用之前,您应该使用文档创建一个模板,并将签名选项卡放在您希望某人签名的位置。
// DocuSign API Walkthrough 08 in C# - Embedded Signing
// To run this sample:
// 1) Create a new .NET project.
// 2) Add 3 assembly references to the project: System, System.Net, and System.XML
// 3) Update the username, password, integrator key, and templateId in the code
// 4) Compile and Run
//
using System;
using System.IO;
using System.Net;
using System.Xml;
using System.Text;
namespace APIWalkthrough08
{
public class EmbeddedSigning
{
// Enter your info:
static string username = "***";
static string password = "***";
static string integratorKey = "***";
static string templateId = "***";
static string roleName = "***";
public static void Main ()
{
string url = "https://demo.docusign.net/restapi/v2/login_information";
string baseURL = ""; // we will retrieve this
string accountId = ""; // will retrieve
string envelopeId = ""; // will retrieve
string uri = ""; // will retrieve
string authenticateStr =
"<DocuSignCredentials>" +
"<Username>" + username + "</Username>" +
"<Password>" + password + "</Password>" +
"<IntegratorKey>" + integratorKey + "</IntegratorKey>" +
"</DocuSignCredentials>";
//
// STEP 1 - Login
//
try {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (url);
request.Headers.Add ("X-DocuSign-Authentication", authenticateStr);
request.Accept = "application/xml";
request.Method = "GET";
HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse ();
StreamReader sr = new StreamReader(webResponse.GetResponseStream());
string responseText = sr.ReadToEnd();
using (XmlReader reader = XmlReader.Create(new StringReader(responseText))) {
while (reader.Read()) { // Parse the xml response body
if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "accountId"))
accountId = reader.ReadString();
if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "baseUrl"))
baseURL = reader.ReadString();
}
}
//--- display results
Console.WriteLine("accountId = " + accountId + "\nbaseUrl = " + baseURL);
//
// STEP 2 - Request Envelope Result
//
// Construct an outgoing XML request body
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>" + templateId + "</templateId>" +
"<templateRoles>" +
"<templateRole>" +
"<email>" + username + "</email>" + // NOTE: Use different email address if username provided in non-email format!
"<name>Name</name>" + // username can be in email format or an actual ID string
"<roleName>" + roleName + "</roleName>" +
"<clientUserId>1</clientUserId>" +
"</templateRole>" +
"</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();
sr = new StreamReader(webResponse.GetResponseStream());
responseText = sr.ReadToEnd();
using (XmlReader reader = XmlReader.Create(new StringReader(responseText))) {
while (reader.Read()) { // Parse the xml response body
if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "envelopeId"))
envelopeId = reader.ReadString();
if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "uri"))
uri = reader.ReadString();
}
}
//--- display results
Console.WriteLine("Envelope sent!. EnvelopeId is --> " + envelopeId);
//
// STEP 3 - Get the Embedded Console Sign View
//
// construct another outgoing XML request body
string reqBody = "<recipientViewRequest xmlns=\"http://www.docusign.com/restapi\">" +
"<authenticationMethod>email</authenticationMethod>" +
"<email>" + username + "</email>" + // NOTE: Use different email address if username provided in non-email format!
"<returnUrl>http://www.docusign.com</returnUrl>" + // username can be in email format or an actual ID string
"<clientUserId>1</clientUserId>" +
"<userName>Name</userName>" +
"</recipientViewRequest>";
// append uri + "/views/recipient" to baseUrl and use in the request
request = (HttpWebRequest)WebRequest.Create (baseURL + uri + "/views/recipient");
request.Headers.Add ("X-DocuSign-Authentication", authenticateStr);
request.ContentType = "application/xml";
request.Accept = "application/xml";
request.ContentLength = reqBody.Length;
request.Method = "POST";
// write the body of the request
byte[] body2 = System.Text.Encoding.UTF8.GetBytes (reqBody);
Stream dataStream2 = request.GetRequestStream ();
dataStream2.Write (body2, 0, reqBody.Length);
dataStream2.Close ();
// read the response
webResponse = (HttpWebResponse)request.GetResponse();
sr = new StreamReader(webResponse.GetResponseStream());
responseText = sr.ReadToEnd();
using (XmlReader reader = XmlReader.Create(new StringReader(responseText))) {
while (reader.Read()) { // Parse the xml response body
if((reader.NodeType == XmlNodeType.Element) && (reader.Name == "url"))
url = reader.ReadString();
}
}
Console.WriteLine("Embeded View Result --> " + responseText);
System.Diagnostics.Process.Start(url);
}
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);
}
}
}
} // end main()
} // end class
} // end namespace
答案 1 :(得分:0)
如果你还没有这样做,我建议你查看DocuSign REST API指南:http://www.docusign.com/sites/default/files/REST_API_Guide_v2.pdf - 因为它包含了实现目标所需的所有信息(比我更详细)这里将描述。
要通过REST API创建/发送信封,您将使用POST /accounts/{accountId}/envelopes
,如API指南的“发送信封或创建草稿信封”部分所述。对于您要在应用程序中签名嵌入/捕获的每个收件人,请务必为收件人设置 clientUserId 属性 - 创建信封请求中收件人的此属性的存在是什么告诉DocuSign您的应用程序将启动/促进收件人的签名体验(因此DocuSign不会向收件人发送签名邀请电子邮件)。
当收件人在您的应用程序中查看/签署信封时,您将使用POST /accounts/{accountId}/envelopes/{envelopeId}/views/recipient
,如API指南的“ POST收件人视图”部分所述 - 检索可用于启动/启动收件人的DocuSign签名会话的URL。使用此URL作为iFrame的目标将在框架内显示DocuSign签名会话。在 POST收件人视图请求中,您设置 returnUrl 属性以指示DocuSign在其嵌入式/强制签名会话完成时应重定向签名者的位置。当重定向到此URL时,DocuSign将附加查询字符串参数(“事件”),该参数的值将指示签名会话的结果。 API指南的第167页的 returnUrl 参数说明列出了此参数的可能值。您的应用程序(即您指定的重定向页面)可以查询此参数值以了解签名会话的结果,并采取任何必要的操作。
关于身份验证 - 用于验证信封发件人的信息是通过每个API请求的 X-DocuSign-Authentication 标头提供的。此外,可以为每个收件人指定特定形式的身份验证 - 例如,访问代码,电话身份验证,ID检查,SMS身份验证 - 您可以通过为“每个收件人”中的每个收件人设置适当的属性来为每个收件人指定身份验证方法创建信封“请求。 (API指南包含有关这些属性的信息。)