Solved

Error received when passing data to a webservice

Posted on 2014-04-29
3
367 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 500 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

When ransomware hits your clients, what do you do?

MSPs: Endpoint security isn’t enough to prevent ransomware.
As the impact and severity of crypto ransomware attacks has grown, Webroot fought back, not just by building a next-gen endpoint solution capable of preventing ransomware attacks but also by being a thought leader.

Question has a verified solution.

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

Suggested Solutions

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…

751 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