WCF binds netTcpBinding to host on IIS, wcfnettcpbinding
Continue to use the WCF Service library Wettery. WcfContract. Services in the previous article.
WCF binds netTcpBinding to host the console application
Server
Add the WCF Service Application Wettery. WcfIISHost. Services. Add two WCF Services, GameService. svc PlayerService. svc, delete the contract interface and. cs embedded file, and leave only the. svc File
We use Autofac to inject the contract/service dependency, which is referenced by Nuget.
Install-Package Autofac.Wcf
Modify the ServiceHost declaration of two svc files
<%@ ServiceHost Language="C#" Debug="true" Service="Wettery.WcfContract.Services.IGameService, Wettery.WcfContract.Services" Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>
<%@ ServiceHost Language="C#" Debug="true" Service="Wettery.WcfContract.Services.IPlayerService, Wettery.WcfContract.Services" Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>
Add Global. asax, modify the Application_Start method, and inject dependencies when the program starts.
Protected void Application_Start (object sender, EventArgs e) {var builder = new ContainerBuilder (); // register other Dependencies //.... // register the dependency of the WCF Service var wcfAssembly = typeof (GameService ). assembly; builder. registerAssemblyTypes (wcfAssembly ). asImplementedInterfaces (). asSelf (); var container = builder. build (); AutofacHostFactory. container = container ;}
Server Configuration
Modify system. serviceModel section in Web. config
<System. serviceModel> <services> <service name = "Wettery. wcfContract. services. gameService "behaviorConfiguration =" mex "> <endpoint address =" "binding =" netTcpBinding "contract =" Wettery. wcfContract. services. IGameService "bindingConfiguration =" netTcpBindingConfig "> </endpoint> <! -- Net. tcp binding provides metadata --> <endpoint address = "mex" binding = "mexTcpBinding" contract = "IMetadataExchange"/> </service> <service name = "Wettery. wcfContract. services. playerService "behaviorConfiguration =" mex "> <endpoint address =" "binding =" netTcpBinding "contract =" Wettery. wcfContract. services. IPlayerService "bindingConfiguration =" netTcpBindingConfig "> </endpoint> <! -- Net. tcp binding provides metadata --> <endpoint address = "mex" binding = "mexTcpBinding" contract = "IMetadataExchange"/> </service> </services> <bindings> <netTcpBinding> <binding name = "netTcpBindingConfig" transferMode = "Buffered" portSharingEnabled = "true"> <readerQuotas maxStringContentLength = "6553600"/> <security mode = "None"/> </binding> </netTcpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name = "mex"> <serviceMetadata httpGetEnabled = "true" httpsGetEnabled = "false"/> <serviceDebug enabled =" true "/> </behavior> </serviceBehaviors> </behaviors> </system. serviceModel>
IIS configuration
Because IIS does not support non-HTTP by default, to enable the non-HTTP function, select HTTP and non-HTTP activation in "enable or disable Windows function ".
Compile the WCF application, add a site in IIS, point to the WCF directory, bind two protocols, use port 21335 for HTTP, and use port 21336 for NET. TCP.
Site, enable the net. tcp protocol in Advanced Settings
Client Test
Use wcftestclient to test the metadata address of the WCF Service:
Http: // localhost: 21335/GameService. svc
Http: // localhost: 21335/PlayerService. svc
If an error occurs in Invoke
You can enable these two services.
Net. Tcp Listener Adapter
Net. Tcp Port Sharing Service