WCF binds netTcpBinding to host on IIS, wcfnettcpbinding

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.