0

I developed a C# console application that consumes a WCF service. All works fine on the local machine. When I created the set up files and distributed the exe and exe.config files, the application errors out on other machines on the same network with the below error:

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state..

The WCF service endpoint URL - http://inblrlwssc251.wdf.corp:7980/AfariaService/Server is accessible form other machines as well. Unsure what can be going wrong.

The configuration for the service looks as below, I use the WSHTTP binding:

 <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true" logMalformedMessages="true"
          logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
    <bindings>
      <netNamedPipeBinding>
        <binding name="NetNamedPipeBinding_IServerService" />
      </netNamedPipeBinding>
      <netTcpBinding>
        <binding name="NetTcpBinding_IServerService">
          <security mode="Message" />
        </binding>
      </netTcpBinding>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IServerService" />
      </wsHttpBinding>
    </bindings>
    <!-- 
      Modify the "adress" in each of the endpoint tags based on where the Afaria API service is hosted
    -->
    <client>
      <endpoint address="http://inblrlwssc251:7980/AfariaService/Server"
          binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IServerService"
          contract="AfariaServerService.IServerService" name="WSHttpBinding_IServerService">
      </endpoint>
      <endpoint address="net.tcp://inblrlwssc251:7982/AfariaService/Server"
          binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IServerService"
          contract="AfariaServerService.IServerService" name="NetTcpBinding_IServerService">
      </endpoint>
      <endpoint address="net.pipe://localhost/AfariaService/Server"
          binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipeBinding_IServerService"
          contract="AfariaServerService.IServerService" name="NetNamedPipeBinding_IServerService">
      </endpoint>
    </client>
  </system.serviceModel>

Any help or a pointer in the right direction will be very much appreciated.

user2856028
  • 43
  • 1
  • 9
  • The error you mentioned is not the cause of the issue. The question is, how does it get into the faulted state? It's impossible to tell without catching and logging the original exception. I think you do catch the exception, but you still try to use the client for other calls. (An exception during a WCF call puts your client into the faulted state. When you try to use this client again, that's when you get the exception that you cannot use it anymore.) – fejesjoco Nov 28 '14 at 14:38
  • @fejesjoco is on the right path. Any *unhandled* exception in the service will put the channel in a faulted state, and a faulted channel cannot be used - a new one will need to be recreated. Check your service - look into any logs you have, check the event viewer to see if anything is logged there and enable WCF tracing are all ways to research the root cause. – Tim Nov 28 '14 at 19:23
  • thanks fejesjoco and Tim, the issue is resolved. I did not pass the right credentials to access the WCF service. – user2856028 Dec 02 '14 at 14:46

1 Answers1

0

I know that this is old and you said it is resolved, but for posterity's sake this is not typically the result of passing incorrect credentials. Normally this is a result of the response from the server responding with more data that you've configured to accept in your buffers, exceeding the maxitemsinobject graph, or the response from the server taking too long, which causes an exception, which is handled... and this exception is the result of the next call (as fejesjoco and Tim pointed out).

When this occurs, it is best to reinitialize the client/serviceclient object (for this api, also call initContext) and then try the call again.