WCF Error: The requested service could not be activated

If and when a WCF client receives any one of the following errors…

The requested service, ‘net.tcp://mydomain:808/Services/MyService.svc’ could not be activated. See the server’s diagnostic trace logs for more information.

OR

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

the problem may be due to the .config file of the WCF Host.

Try removing the address from the endpoint that you are having problems with. For example:
The original .config may look something like this (Note the address value of the net.tcp service endpoint).

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="MyService">
        <endpoint address="net.tcp://mydomain:808/Services/MyService.svc" 
                  binding="netTcpBinding" 
                  contract="IMyService"/>
        
      </service>
    </services>
    ....
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

See what happens if you remove the endpoint address like this:

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="MyService">
        <endpoint address="" 
                  binding="netTcpBinding" 
                  contract="IMyService"/>
        
      </service>
    </services>
    ....
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

I have no idea why the removal of the address resolved the error the client receives (It did for me, anyway) – nor can I figure out why explicitly defining the url to the service throws an error. In my little knowledge of WCF, it seems it would be the other way around.

If you can fill me in as to why removing the service’s endpoint address from the hosts .config file can, in certain cases, resolve exception errors, please leave me a message :)

For the record, the errors mentioned above can also be thrown when the router that the WCF Host lives behind has not opened its ports to allow for the Net.Tcp protocol.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s