WebException - ConnectFailure

M

MikeB

Hello all, I keep getting inconsistant connection failures and can not
figure it out. I have a strong signal (through ATT Network) however I can
run a transaction and it will fail sometimes while the next time it goes
through without a problem. Any ideas, below is my connection code:

Also, this is CF1.1

//Apply Certificate Policy
ServicePointManager.CertificatePolicy = new AcceptUntrustedSSLPolicy();

//URL = HTTPS://www.mysite.com
req = (HttpWebRequest)System.Net.WebRequest.Create(sURL);

//enncode the form data string into a byte array
b = System.Text.Encoding.ASCII.GetBytes(sPayLoad);

//Indicate Method as Post and set the Length and Type of Data being Posted
req.Method = "POST";
req.ContentType = "UTF197/TCS";
req.KeepAlive = false;
req.AllowWriteStreamBuffering = true;
req.Timeout = 60000;

req.Headers.Add("POST","/controller HTTP/1.0");
req.Headers.Add("Auth-MID:" + _strXXNbr);
req.Headers.Add("Auth-TID:" + _strXXID);
req.Headers.Add("Auth-User:" + _strUserID);
req.Headers.Add("Auth-Password:" + _strPassword);
req.Headers.Add("Stateless-Transaction:true");
req.Headers.Add("Header-Record:false");

s = req.GetRequestStream();
s.Write(b, 0, b.Length);
s.Close();

res = (HttpWebResponse)req.GetResponse();

//read the returned page and place into a text control
sr = new StreamReader(res.GetResponseStream());

//Read Result
_strFullResponse = sr.ReadToEnd();

//close opened connections
sr.Close();
res.Close();

return _strFullResponse;
 
G

Guest

Where exactly is the method failing. Try stepping through the code also
place you code in a try catch finally block. Your close methods should be
enclosed in the finally to ensure the resources are closed when the method
fails.

Rick D.
Contractor
 
M

MikeB

I have stepped though and it is in a try catch, I just cut all of it out in
this post. It is fails on this line:

res = (HttpWebResponse)req.GetResponse();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top