Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error received when passing data to a webservice

Posted on 2014-04-29
3
Medium Priority
?
371 Views
Last Modified: 2014-04-30
Hi.

I am passing data to a web service, via another web service, but when I do, I receive the following error:

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond <<IP address of web service>>

Here is the code I used to pass the data :

 Uri address = new Uri("http://webservice_address");

                        HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;  
 
                        request.Method = "POST";  
                        request.ContentType = "application/x-www-form-urlencoded";  
 
                        StringBuilder data = new StringBuilder();  
                        data.Append("source=" + HttpUtility.UrlEncode(strCompany));  
                        data.Append("&user=" + HttpUtility.UrlEncode(strusername));  
                        data.Append("&pass=" + HttpUtility.UrlEncode(strpassword));
                        data.Append("&phone_number=" + HttpUtility.UrlEncode(strPhoneNumber));
                        data.Append("&phone_code=" + HttpUtility.UrlEncode(strPhoneCode));
                        data.Append("&first_name=" + HttpUtility.UrlEncode(strFirstName));
                        data.Append("&last_name=" + HttpUtility.UrlEncode(strLastName));
                        data.Append("&email=" + HttpUtility.UrlEncode(strEmail));

                        byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());  
                        request.ContentLength = byteData.Length;  
                        using (Stream postStream = request.GetRequestStream())  
                        {  
                            postStream.Write(byteData, 0, byteData.Length);  
                        }

                        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                        {

                            string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

                            FFIResponse = responseString;
                            string[] parts = responseString.Split(new char[] { '|' });

                            LeadID = parts[2];

                            LI.Insert_ID(_lead.LeadID, Convert.ToInt32(LeadID));

                           // return responseString;
                            DateTime now = DateTime.Now;
                            StringResult = "Lead : " + LeadID + " Passed sucessfully on : " + now;

                        }

Open in new window

0
Comment
Question by:Jasmin01
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 total points
ID: 40029020
Well, I think the problem is clear... are you sure you can connect to the service's URL? Are you from behind a firewall or somewhat else?
0
 

Author Comment

by:Jasmin01
ID: 40029025
I have taken the data and passed the parameters directly from my browser, and it went through without error, but when I tried to send it via my web service, it does not work.
0
 

Author Closing Comment

by:Jasmin01
ID: 40031867
I think the problem was with the hosting party.  It is working now, which could only mean that they fixed something on their side
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question