catch(Exception ex)
{
//do what you want here
//When type of exception is System.Web.Services.Protocols.SoapException
//if (ex.Code.Name.Equals("Client"))
//{
// msg = "service's function not exist";
//}
//else if (ex.Code.Name.Equals("Server"))
//{
// msg = "function error"
//}
//else
//{
// msg = "unknown";
//}
//MessageBox.Show(msg, "error", MessageBoxButtons.OK);
**But ex is not System.Web.Services.Protocols.SoapException so I cannot call ex.Code.Name.Equals("Client")**
//When System.Net.WebException
//switch (ex.Status)
//{
// case System.Net.WebExceptionStatus.ConnectFailure:
// do some thing
break;
// case System.Net.WebExceptionStatus.Timeout:
//do some thing
break;
// case System.Net.WebExceptionStatus.ProtocolError:
switch (((System.Net.HttpWebResponse)ex.Response).StatusCode)
{
case System.Net.HttpStatusCode.NotFound:
//do some thing
break;
case System.Net.HttpStatusCode.ServiceUnavailable:
//do some thing
break;
case System.Net.HttpStatusCode.Unauthorized:
//do some thing
break;
default:
//do some thing
break;
}
break;
default:
//do some thing
break;
}
}
But Exception is not System.Net.WebException. So cannot call ex.Status
My problem:
I have a Smartclient software include WindowsForm as client and a webservice as server. Client and Server both are n-tiers application I have tested and found that has any problem when call service from Client
- in app.config: service's path wrrong . I catch System.NotSupportedException
- Or when the server cannot connect: System.Net.WebExceptionStatus
- Server's webconfig is wrong : System.InvalidOperationException
- Service throws an exception: System.Web.Services.Protocols.SoapException ...
My Idea
I call the Exception that as representative of all other exception types is representativeAlException I have namespace : Common and two classese representativeAlException.cs and BusinessExceptionHandler.cs
Make a common function with a param as (representativeAlException ex)
try
{
Err_LogCheck.Service1.Service1 service = new Err_LogCheck.Service1.Service1();
return service.getDeviceByZero(ZERO);
}
catch (Common.representativeAlException ex)
{
Common.BusinessExceptionHandler.ProcessException(ex);
}
What I want to do
Where the service is called. Only one catch block can handler for all type of Exception
in ProcessException(representativeAlException ex) function
switch (ex)
{
case System.InvalidOperationException:
//Do some thing
break;
case System.NotSupportedException:
//Do some thing
break;
case System.Web.Services.Protocols.SoapException:
//do some thing
break;
...
...