473,383 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

C# WSE2 can't get HTTP Status Code, please help

Hi folks,

I have what seems like a fairly straight forward question which im sure has a simple answer as well..but i can't seem to find it. I'm using the Microsoft .NET WSE2 library in order to call web services. When it fails to connect or server returns 500 error, etc.. i can see the message in teh exception but i can't seem to find a way to get at the actual '500' code or '200' or whatever code has occured. Here is a snippet from my code:

try {
SoapWebRequest request = new SoapWebRequest(url);
...bunch of code here.......
WebResponse response = request.GetResponse();
}
catch (Exception ex) {
Console.WriteLine(ex.ToString());
}

I've tried looking at the exception object, the request and response objects but no matter where i look i can't find the HttpStatusCode. I know that if i had an HttpWebResponse object, it has a StatusCode property....but WebResponse is not a HttpWebResponse object.

Can someone out there help me out?
Thanks so much.

-Dave
Sep 8 '08 #1
7 3983
Plater
7,872 Expert 4TB
Frequently the request.GetResponse(); can be type-casted into a better object.

Which is to say that a SoapWebResponse that inherits from WebResponse is being returned, but casted as a WebResponse.
Try something like this:

SoapWebResponse response = (SoapWebResponse)request.GetResponse();
Sep 8 '08 #2
Thanks for the suggestion Plater but i've already tried this. There is no HTTPStatus property on the SoapWebResponse object... nor can i find it on any other properties of this object.

There has to be some way to do this...
Sep 9 '08 #3
Plater
7,872 Expert 4TB
Well it's going to be "200 OK", since I believe it throws a WebException if it gets any other status.
After having re-read your message, I see you are trapping with the base Exception type. Try catching specific exception objects (Like the WebException)
Sep 9 '08 #4
Already tried that as well. :(
Keep in mind, i'm traversing the exception in visual studio debug mode, so i can see all properties of the exception object regardless of what type is in the catch statement...but i just can't seem to find any properties etc which will give me the http code. I don't want to pull it out of the exception message text as this is not reliable.
Sep 9 '08 #5
Plater
7,872 Expert 4TB
Hmm doesn't look like you can get at it without parsing the message.
Sep 9 '08 #6
That's what i was afraid of. In my opinion, it's absolutely ridiculous that the http status code cannot be retrieved. I would think this is something frequently needed by developers. It's a significant oversight on microsoft's part....
Sep 9 '08 #7
boyank
5
It's easier than you think. Just catch the WebException and do some casting like so:

catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;

// Displays "NotFound" for 404
MessageBox.Show(response.StatusCode);
}
Nov 18 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Aliandro | last post by:
Hi I am really stuck and need some expertise help please. I have an XML file: <XML> <USER_INFO> <USERNAME>username</USERNAME> <PASSWORD>password%</PASSWORD> </USER_INFO> <SITE_INFO>...
0
by: Hai Ta | last post by:
Please help We have been stuck for the past 2 weeks in trying to implement a webservice using WSE2 such that consumer can access with the following soap header. <?xml version="1.0"...
0
by: JMZ | last post by:
We have a web service that is called directly from clients via an IE hosted Windows control. We issue our own certificates and use them as part of the authentication process as well as in WSE2....
0
by: Zaffar | last post by:
I am trying use UserNameToken with WSE2. There is always some error or other. Like Actually the problem lies in Web.Config Settings. Does any one know all the required settings for WSE2 and...
0
by: Sid DeLuca | last post by:
I'm modifying the WSE2 HOL sample to develop my web service. I'm able to get the client application's username token encrypted on the way out (outputTrace.webinfo), but not on receipt from the...
0
by: AC | last post by:
I got a requriement of sending something from a winform client written by c# to a server implied by Java. And I tried to send the content using SoapReceivers and SoapSender, WSE2.0. When I change...
0
by: David G | last post by:
I have a web service originally written to use soap.tcp transport in WSE2 that now uses http transport under WSE3. The WSE2 method looked like public IndividualLookupResponse...
8
by: rajesh | last post by:
< script language = javascript c =...
2
by: abdiphp | last post by:
Hi every one, I need help to get the this going, Itried whatever I can but could not get the right xpath to this xml I need to get the value of this node (IMAGE_FILE) and this is not...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.