示例#1
0
        public async Task <ActionResult> SendDocumentforSign(Recipient recipient, HttpPostedFileBase UploadDocument)
        {
            byte[] fileBytes;
            using (Stream inputStream = UploadDocument.InputStream)
            {
                MemoryStream memoryStream = inputStream as MemoryStream;
                if (memoryStream == null)
                {
                    memoryStream = new MemoryStream();
                    inputStream.CopyTo(memoryStream);
                }
                fileBytes = memoryStream.ToArray();
            }

            var DocumentBase64 = System.Convert.ToBase64String(fileBytes);

            DocuSignRequestData inputModel = new DocuSignRequestData();

            inputModel.fileData   = DocumentBase64;
            inputModel.recipients = recipient.Email;

            using (var client = new HttpClient())
            {
                // as of now the url is hardcoded we can get it from above call of geturl.
                // client.PostAsync()
                var res = await client.PostAsync("https://localhost:44349/api/DocuSignPost/SendDocumentforSign", new StringContent(JsonConvert.SerializeObject(inputModel), Encoding.UTF8, "application/json"));

                try
                {
                    res.EnsureSuccessStatusCode();
                    //res.Result.EnsureSuccessStatusCode();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }

            //using (var client = new HttpClient())
            //{
            //    //Passing service base url
            //    client.BaseAddress = new Uri(Baseurl);

            //    client.DefaultRequestHeaders.Clear();
            //    //Define request data format
            //    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            //    //Sending request to find web api REST service resource GetAllEmployees using HttpClient
            //   // HttpResponseMessage Res = await client.PostAsync("https://localhost:44349/api/DocuSignPost");

            //    //Checking the response is successful or not which is sent using HttpClient
            //    if (Res.IsSuccessStatusCode)
            //    {
            //        //Storing the response details recieved from web api
            //        var Response = Res.Content.ReadAsStringAsync().Result;
            //    }
            //}

            return(View());
        }
        public ActionResult SendDocumentforSign(Recipient recipient, HttpPostedFileBase UploadDocument)
        {
            byte[] fileBytes;
            using (Stream inputStream = UploadDocument.InputStream)
            {
                MemoryStream memoryStream = inputStream as MemoryStream;
                if (memoryStream == null)
                {
                    memoryStream = new MemoryStream();
                    inputStream.CopyTo(memoryStream);
                }
                fileBytes = memoryStream.ToArray();
            }

            var DocumentBase64 = System.Convert.ToBase64String(fileBytes);

            DocuSignRequestData inputModel = new DocuSignRequestData();

            inputModel.fileData    = DocumentBase64;
            inputModel.Email       = recipient.Email;
            inputModel.Name        = recipient.Name;
            inputModel.Description = recipient.Description;

            //Note: be replcaed by actual webhook URL of caller API.
            inputModel.returnUrl = "http://callerapi.azurewebsites.net/api/SignedDocumentRecvd/ReciveSignedDoc";

            using (var client = new HttpClient())
            {
                //var res = await client.PostAsync("https://localhost:44349/api/DocuSignPost/SendDocumentforSign", new StringContent(JsonConvert.SerializeObject(inputModel), Encoding.UTF8, "application/json"));
                HttpResponseMessage res = client.PostAsync("https://dssapi.azurewebsites.net/api/DocuSignPost/SendDocumentforSign", new StringContent(JsonConvert.SerializeObject(inputModel), Encoding.UTF8, "application/json")).Result;

                // HttpResponseMessage res = client.PostAsync("https://localhost:44349/api/DocuSignPost/SendDocumentforSign", new StringContent(JsonConvert.SerializeObject(inputModel), Encoding.UTF8, "application/json")).Result;
                Task <string>    responseesult = res.Content.ReadAsStringAsync();
                DocuSignResponse obj           = JsonConvert.DeserializeObject <DocuSignResponse>(responseesult.Result.ToString());

                if (obj != null && !string.IsNullOrEmpty(obj.EnvelopeId))
                {
                    ViewBag.SucMessage = "Document sent successully";
                }
                try
                {
                    res.EnsureSuccessStatusCode();
                    //res.Result.EnsureSuccessStatusCode();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }



            return(View());
        }