Solved

Error received when passing data to a webservice

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

For some reason Google Apps has decided to reserve 'www' for your new domain which results in an error when trying to map the web address 'www' to a certain site in your Google Sites. The error is 'this address is already being used' and after some …
To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
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…

680 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