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
Solved

Error received when passing data to a webservice

Posted on 2014-04-29
3
364 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

789 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