Web services with .NET Compact Framework

  • Thread starter Thread starter Davie
  • Start date Start date
D

Davie

I have done quite a bit of development with the .NET compact framework in
the past. I am coming back to a problem i had a while ago relating to web
services.


Basically, when the application tries to download data from a webservice, I
occasionally get a server returned type: text/html. This causes the
application to crash and die on me. I'm following the examples which have
been given in most .NET books by microsoft.

I am looking for an example which is complete and handles all kinds of
connection related problem. The frustrating thing is, MSN messenger works
fine on my mobile, i know it must have exception handling in that. I'm
wanting something reliable that I can download data on request.

Please can you advise me on this.

Many thanks.
 
I'm not 100% sure on what you are asking but if it is how to handle Web
exceptions in C# maybe something like the following should help: (e is the
WebException object)

StringBuilder _sb = new StringBuilder();

if (e.Response != null)

{

System.Net.HttpWebResponse _rep = (System.Net.HttpWebResponse)e.Response;

_sb.Append(MyResources.Strings["server_msg"] + ": ");

if (_rep.Server.Length == 0)

{

_sb.Append(MyResources.Strings["unknown_msg"]);

}

else

{

_sb.Append(_rep.Server);

}

_sb.Append("\n" + MyResources.Strings["statuscode_msg"] + ": " +
_rep.StatusCode);

_sb.Append("\n" + MyResources.Strings["statusdescription_msg"] + ": " +
_rep.StatusDescription);

_sb.Append("\n" + MyResources.Strings["host_msg"] + ": " +
_rep.ResponseUri.Host);

_sb.Append("\n" + MyResources.Strings["hostnametype_msg"] + ": " +
_rep.ResponseUri.HostNameType.ToString());

_sb.Append("\n" + MyResources.Strings["port_msg"] + ": " +
_rep.ResponseUri.Port);

if (_rep.ResponseUri.HostNameType == UriHostNameType.Dns)

{

_sb.Append("\n\n" + MyResources.Strings["tryusingipaddress_msg"]);

}

_rep.Close();

}

else

{

_sb.Append(e.Message);

}

//Display the messagebox if the flag is set to true.

if (displayError)

{

MessageBox.Show(_sb.ToString(), MyResources.Strings["weberror_title"]);

}

return _sb.ToString();

Formatting sucks using Outlook!

Simon.
 
Getting a text/html response is normally because the server hosting the
webservice tried to display an error page, rather than returning a
text/xml response.

When I get these, I try to make sure that I'm connecting to the correct
URL, and that the web server and web service are actually working.

R.
 
Back
Top