I am using WCF service with Winform client. I am creating a data cache by calling WCF service multiple times.
one of my service call is failing because of error...
The communication object, System.ServiceModel.Security.SecuritySessionClientSettings1+ClientSecurityDuplexSessionChannel[System.ServiceModel.Channels.IDuplexSessionChannel], cannot be used for communication because it is in the Faulted state.`
code block, which is throwing error...
return _wcfClient.GetGroups().ToList());
This error behavior is random. Sometimes it works without any issue and sometimes it throw given error I tired to debug the issue but client call never reach to WCF service.
Can anyont help me to understand why this is happening and how can I fix it.
UPdated question with code:
I am using casle windsor DI to resolve dependencies. that's how registering service with DI...
container.Register(Component.For<IWCFDataService>()
.AsWcfClient(DefaultClientModel.On(
WcfEndpoint.ForContract<IWCFDataService>().FromConfiguration("Binding_IWCFDataService")))
);
Then dependencies will be injected in class constructor
Code to call service
public List<string> SomePRoperty
{
get
{
lock (_lockObjectSomePRoperty)
{
return _localvariable ?? (_localvariable = wcfClientResolvedFromDI.GetGroups().ToList());
}
}
set { _localvariable = value; }
}
This error happens in case you pass an object in an invalid state. For examle, say GetGroups returns a collection of Group objects, such that Group contains an enum field, say, GroupType. Then if the server side prepares the collection with an invalid enum value, say, (GroupType)36252, while C# doesn't throw an exception on such conversion (see Why does casting int to invalid enum value NOT throw exception?), the stricter WCF throw a security-related exception, as if something messed with your values.