2

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; }
        }
Abhash786
  • 881
  • 2
  • 24
  • 53
  • Please provide full code from where you calling the service. – Amit Singh Mar 03 '16 at 06:23
  • Please see updated question – Abhash786 Mar 03 '16 at 06:44
  • 1
    Hard to figure out without more details. Plain guessing here: what is the timeframe between requests. This is a DuplexSession, there may be many causes but try to see if it is not simply caused by channel being closed due to inactivity. You may then introduce a "hearbeat" requests to keep the channel alive and solve the problem. Other cause may be that you are trying to push too much data in one of your requests and channel faults, you should then send your data in smaller chunks (multiple requests). – Tobiasz Mar 03 '16 at 06:49

1 Answers1

0

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.

erezmk
  • 79
  • 8