System.ServiceModel.ServiceHost, cannot be used for communication because it is in the Faulted state
Asked Answered
C

5

13

Receiving this error when trying to work with the queue:

Unexpected error occured: The communication object, System.ServiceModel.ServiceHost, cannot be used for communication because it is in the Faulted state. at System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)

How to overcome it?

Update: answer to my solution posted at the end

Conlen answered 14/8, 2013 at 11:25 Comment(3)
any chance of showing some of the code :)Mansuetude
i solved, and decided to post the answer:) Didn't find this solution on net before, so decided to share:)Conlen
It would be better to post your solution as an answer and then mark it as such. This helps clarity for others coming to this page.Microsome
C
8

Update: In my case what helped was:

1) enabling trace logs: http://msdn.microsoft.com/en-us/library/ms732023.aspx

2) in the trace log it wrote this:

Binding validation failed because the binding's ExactlyOnce property is set to true while the destination queue is non-transactional. The service host cannot be opened. Resolve this conflict by setting the ExactlyOnce property to false or creating a transactional queue for this binding.

The answer says it all. Created a transactional queue - everything works :) hope it helps people :)

Conlen answered 9/9, 2013 at 12:24 Comment(0)
M
13

This problem is due to access rights. Start Visual Studio with administrative rights and the problem will be resolved. To start Visual Studio with admin rights right click the Visual Studio icon and select "Run As Administrator".

Mev answered 5/2, 2015 at 1:24 Comment(0)
C
8

Update: In my case what helped was:

1) enabling trace logs: http://msdn.microsoft.com/en-us/library/ms732023.aspx

2) in the trace log it wrote this:

Binding validation failed because the binding's ExactlyOnce property is set to true while the destination queue is non-transactional. The service host cannot be opened. Resolve this conflict by setting the ExactlyOnce property to false or creating a transactional queue for this binding.

The answer says it all. Created a transactional queue - everything works :) hope it helps people :)

Conlen answered 9/9, 2013 at 12:24 Comment(0)
S
2

close your solution, Now follow these steps: 1. Right click on the visual studio. 2. Click on Run as Administrator. 3. Now open your solution. 4. Try running it, your problem will be resolved.

Shindig answered 3/10, 2018 at 18:52 Comment(0)
C
1

From my experience, once a endpoint is in a faulted state, it will not recover on its own and needs to be restarted. There's no way to make that happen from the client side. The host must do it.

On the host side, you can check for a faulted state using code like this:

  While True
      'broken connection case
      If objServiceHost(ii).State <> CommunicationState.Opened Then
        Throw New Exception("SynchronizationWS Service Host failed.") 
        Exit While
      End If
    Next
    Threading.Thread.Sleep(c_SleepTime) 'sleep 1 second before going trying next
  End While

We have a higher level program that monitors the heartbeat of our web service (which runs within a windows service) and if the higher level program finds that the heartbeat has stopped, it will recycle the windows service, restarting the WCF web service.

Command answered 14/8, 2013 at 11:34 Comment(0)
R
0

For me it's because the port was already used by another process, I changed the port and the service worked as usual. I knew this by following the trace logs, just follow steps here: https://learn.microsoft.com/en-us/dotnet/framework/wcf/service-trace-viewer-tool-svctraceviewer-exe

The recap:

  1. add this section to the web.config or app.config file:

    <system.diagnostics>
         <trace autoflush="true" />
         <sources>
                 <source name="System.ServiceModel"
                         switchValue="Information, ActivityTracing"
                         propagateActivity="true">
                 <listeners>
                    <add name="sdt"
                        type="System.Diagnostics.XmlWriterTraceListener"
                        initializeData= "SdrConfigExample.e2e" />
                 </listeners>
              </source>
         </sources>
     </system.diagnostics>
    
  2. run the WCF service to reproduce the error.

  3. open SvcTraceViewer.exe tool, I found it in : C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin. It will open the Microsoft Service Trace Viewer window.

  4. Navigate to the log file (File> Open) named "SdrConfigExample.e2e" which was specified in the XML config above, and is located in the root directory. This will list the errors in more detail and you can find the cause of the exception.

*Tip: You can easily and quickly find files on your computer using everything tool.

Rybinsk answered 13/10, 2021 at 10:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.