Link to home
Start Free TrialLog in
Avatar of pzozulka
pzozulka

asked on

HttpWebResponse: How to determine success or failure

We have a web service that attempts to connect to Authorize.NET to process a payment, see below:
StringBuilder sb = new StringBuilder();
sb.Append("x_method=CC");
sb.Append("&x_type=AUTH_CAPTURE");
sb.Append("&x_delim_data=TRUE");
sb.Append("&x_relay_response=FALSE");
...
ASCIIEncoding Asc = new ASCIIEncoding();
byte[] postBytes = Asc.GetBytes(sb.ToString());

WebClient WC = new WebClient();
ServicePointManager.ServerCertificateValidationCallback = TrustAllCertificateCallback;
HttpWebRequest wrequest = (HttpWebRequest)WebRequest.Create("https://secure.authorize.net/gateway/transact.dll");
wrequest.Timeout = 300000;
wrequest.Method = "POST";
wrequest.ContentType = "application/x-www-form-urlencoded";
wrequest.ContentLength = sb.ToString().Length;

Stream lilriver = wrequest.GetRequestStream();
lilriver.Write(postBytes, 0, postBytes.Length);

HttpWebResponse wresponse = (HttpWebResponse)wrequest.GetResponse();
Stream rstream = wresponse.GetResponseStream();
Encoding enc = System.Text.Encoding.GetEncoding("utf-8");

StreamReader strRead = new StreamReader(rstream, enc);
string result = strRead.ReadToEnd();
wresponse.Close();
strRead.Close();
rstream.Close();

Open in new window

How do I determine if the web service call was successful or not in terms of connectivity? I guess I could check the the contents of the result string in the code above to see if it's null or empty, but is there a better way?
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial