I created a simple wcf service which looks as below, in the service Divide() method trying to create faulted excpetion , when I try to consume Divide() method it goes to catch block which uses faulted exception, but service channel state is opened even after
it throws faulted exception, how to simulate faulted state for service instance for testing
Interface:-
[ServiceContract]
public interface IService1
{
[OperationContract]
int Divide(int n1, int n2);
}
Service implementation:-
public class Service1 : IService1
{
public int Divide(int n1, int n2)
{
try
{
return n1 / n2;
}
catch (DivideByZeroException e)
{
throw new FaultException(e.Message);
}
}
}
Consuming service in console application:-
static void Main(string[] args)
{
ServiceReference1.Service1Client svc = new ServiceReference1.Service1Client();
try
{
svc.Divide(7, 0);
}
catch (FaultException ex)
{
string status = svc.State.ToString(); // here state still shows as "opened" ,expected to be faulted
}
catch (Exception ex)
{
string status = svc.State.ToString();
}
//int a = svc.getvalue(2);
}
}
Member
109 Points
241 Posts
How to simulate WCF service channel into faulted state
Jan 31, 2017 03:32 PM|nrk_hi|LINK
Hi ,
I created a simple wcf service which looks as below, in the service Divide() method trying to create faulted excpetion , when I try to consume Divide() method it goes to catch block which uses faulted exception, but service channel state is opened even after it throws faulted exception, how to simulate faulted state for service instance for testing
Interface:-
Service implementation:-
Consuming service in console application:-
All-Star
17542 Points
3510 Posts
Re: How to simulate WCF service channel into faulted state
Feb 02, 2017 07:26 AM|Chris Zhao|LINK
Hi Nrk_hi,
The communication state is going to faulted sate due to protocol error, unhandled exception or timeout.
reference:
http://stackoverflow.com/a/3574053
https://msdn.microsoft.com/en-us/library/ff183865.aspx
Best Regards,
Chris