My WCF uses the nettcpbinding, the use will be an error, change to BasicHttpBinding, everything is normal
The requested service, ' net.tcp://wcf.xxxxx.com:21336/gameservice.svc ' could not being activated. See the server's diagnostic trace logs for more information.
Then I use the browser to access the SVC, the client requests it again, but not access every few minutes, the error appears
=====================================================================
This problem bothers me for a lot of days, online is also looking for no solution (now want to actually think about the wrong direction, thinking that the configuration has a problem, is actually a WCF service Dependency injection initialization problem)
The key moment still depends on the StackOverflow, a random search to find a solution
AUTOFAC WCFINTEGRATION-WCF Client Service can is activated when communicating over net.tcp
So I used the AUTOFAC.INTEGRATION.WCF to do the dependency injection of the WCF service.
<%@ ServiceHost language="C #" debug="true" Service="Wettery.WcfContract.Services.IGameService, Wettery.WcfContract.Services" Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, AUTOFAC.INTEGRATION.WCF" %>
Initialization of dependencies is done in Global.asax's Application_Start
But Global only applies Http bindings, and TCP bindings can take another approach:
Create a class under App_Code, add a static method public static void AppInitialize (), and this method will be executed automatically when the service starts
Note: Classes containing appinitialize static methods can only be placed under App_Code, and this method must be unique
For more detailed reference:
When AppInitialize method get invoked in ASP?
Failed to activate using the NETTCPBINDING,WCF service