I tried with Timeout properties for uploading document in Docusign through demo url from API. But sometimes the api call returns "The remote server returned an error: (400) Bad Request". I looked into the fiddler debug trace. The XML shows 2 things are errorcode and message "1. errorCode : HOURLY_APIINVOCATION_LIMIT_EXCEEDED. 2. Message : The Maximum no of hourly API Invocations has been exceeded. The hourly limit is 1000".. But it was about only 15 to 20 calls I can continuously upload. After that the bad request will start. Again it starting to upload after some time. I cannot upload the Fidler XML image. It shown it need 10 reputations to post image.
string envdef = "<envelopeDefinition xmlns=\"http://www.docusign.com/restapi\">" + envDef;
string temp = Environment.ExpandEnvironmentVariables("%temp%");
FileStream fileStream = System.IO.File.OpenRead(path);
// build the multipart request body
string requestBodyStart = "\r\n\r\n--BOUNDARY\r\n" +
"Content-Type: application/xml\r\n" +
"Content-Disposition: form-data\r\n" +
"\r\n" +
envdef + "\r\n\r\n--BOUNDARY\r\n" + // our xml formatted envelopeDefinition
"Content-Type: application/x-www-form-urlencoded\r\n" +
"Content-Disposition: file; filename=\"CaptionBookmarkTest - 214744463.doc\"; documentId=1\r\n" +
"\r\n";
string requestBodyEnd = "\r\n--BOUNDARY--\r\n\r\n";
// use baseURL value + "/envelopes" for url of this request
request.Timeout = 1000000;
request = (HttpWebRequest)WebRequest.Create(baseURL + "/envelopes");
request.Headers.Add("X-DocuSign-Authentication", authenticateStr);
request.ContentType = "multipart/form-data; boundary=BOUNDARY";
request.Accept = "application/xml";
request.ContentLength = requestBodyStart.ToString().Length + fileStream.Length + requestBodyEnd.ToString().Length;
request.Method = "POST";
// write the body of the request
byte[] bodyStart = System.Text.Encoding.UTF8.GetBytes(requestBodyStart.ToString());
byte[] bodyEnd = System.Text.Encoding.UTF8.GetBytes(requestBodyEnd.ToString());
Stream dataStream = request.GetRequestStream();
dataStream.Write(bodyStart, 0, requestBodyStart.ToString().Length);
// Read the file contents and write them to the request stream
byte[] buf = new byte[4096];
int len;
while ((len = fileStream.Read(buf, 0, 4096)) > 0)
{
dataStream.Write(buf, 0, len);
}
dataStream.Write(bodyEnd, 0, requestBodyEnd.ToString().Length);
dataStream.Close();
// read the response
request.MaximumAutomaticRedirections = 4;
webResponse = (HttpWebResponse)request.GetResponse();
sr.Close();
responseText = "";
sr = new StreamReader(webResponse.GetResponseStream());
responseText = sr.ReadToEnd();
StreamWriter SW;
SW = System.IO.File.CreateText(temp + "\\upload.XML");
SW.WriteLine(responseText);
SW.Close();
sr.Close();