Solved

Error received when passing data to a webservice

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now