In my scenario, I will be connected to a clustered MSMQ. infact, it doesnt matter if it is clustered or not.
When the MSMQ service is down, the client will be faulted.
I know I can subscribe to the servicehost's OnFaulted event however, there does not appear to be a way to investigate to see the reason for the fault.
The service providing the processing of messages is not of concern here, as the MSMQ service could directly be shutdown, and as a result causes the clients connected to be faulted.
Any ideas how to obtain the reason for the disconnection? I mean, I am looking for something like a Communication Exception type reason. I want to be able to capture that and be able to reconnect my client rather than having to restart manually.
On the client side, you could use try{} and catch(){} block to catch various exception type, for example, in the catch block, you could check the state of your WCF client object, if it is in a faulted state, then you can create a new one to connect to WCF
service again, something as follows:
ServiceClient client = new ServiceClient();
try {
client.Operation();
}
catch(Exception ex)
{
if (client.State == CommunicationState.Faulted)
{
client.Abort();
client = new ServiceClient();
}
}
ahmedilyas
Member
414 Points
588 Posts
Detect WCF Faulted reason
May 04, 2012 01:13 AM|LINK
In my scenario, I will be connected to a clustered MSMQ. infact, it doesnt matter if it is clustered or not.
When the MSMQ service is down, the client will be faulted.
I know I can subscribe to the servicehost's OnFaulted event however, there does not appear to be a way to investigate to see the reason for the fault.
The service providing the processing of messages is not of concern here, as the MSMQ service could directly be shutdown, and as a result causes the clients connected to be faulted.
Any ideas how to obtain the reason for the disconnection? I mean, I am looking for something like a Communication Exception type reason. I want to be able to capture that and be able to reconnect my client rather than having to restart manually.
Thanks!
Peter pi - M...
Star
12871 Points
1786 Posts
Re: Detect WCF Faulted reason
May 07, 2012 02:39 AM|LINK
On the client side, you could use try{} and catch(){} block to catch various exception type, for example, in the catch block, you could check the state of your WCF client object, if it is in a faulted state, then you can create a new one to connect to WCF service again, something as follows:
ServiceClient client = new ServiceClient(); try { client.Operation(); } catch(Exception ex) { if (client.State == CommunicationState.Faulted) { client.Abort(); client = new ServiceClient(); } }If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
ahmedilyas
Member
414 Points
588 Posts
Re: Detect WCF Faulted reason
May 07, 2012 08:38 AM|LINK
thanks. im very well aware of the try catch block....
but because this is a disconnected service (MSMQ) it is NOT possible for the client to pick up any errors
so if the service faults, then I only can see the faulted event being raised but unable to determine the type of exception or what the exception was
aaroncheung
Member
70 Points
15 Posts
Re: Detect WCF Faulted reason
May 11, 2012 06:29 AM|LINK
Not sure there is a way to get the reason. But you can reconnect as blow
http://nahidulkibria.blogspot.com/2008/05/knowing-when-wcf-service-in-fault-state.html