WCF: How to host nettcpbinding on IIS7

Source: Internet
Author: User
Tags msmq

Summary: Starting with IIS 7, IIS has added support for non-HTTP protocols. As a result, the bindings of non-HTTP protocols such as nettcpbinding can be hosted directly on IIS since IIS 7. This article describes how to configure WCF NetTcpBinding on IIS and provides a more in-depth discussion of how it works.

Windows Process Activation Service

is how IIS snooping works on the HTTP protocol. The HTTP protocol listener is done with the help of the kernel-mode. sys

Starting with IIS7, IIS has also added support for non-HTTP protocols. For services that use non-HTTP protocols but need to be deployed in IIS to take advantage of the excellent management capabilities of IIS, such as WCF services, is a great boon. IIS7 can support a variety of non-HTTP protocols, such as NET.TCP,NET.MSMQ, Net.pipe, and so on. Because HTTP. SYS does not listen on a port that is not a protocol. For non-HTTP protocols, there are separate Windows Serivce to listen on. For example, the net.tcp protocol is monitored by the net.tcp Port sharing service and NET.TCP Listener adapter services and hosted in SMSvcHost.exe.

After the split, was not only processing the HTTP request, it can also handle requests for non-HTTP protocols. The HTTP request was intercepted by the. SYS and was passed to the HTTP manager in W3SVC before being passed to was, but the other requests were forwarded to the Configuration Manager and the process manager through the adapter interface of the was listener, without W3SVC.

For the introduction of was, refer to here:

http://msdn.microsoft.com/en-us/library/ms734677 (v=vs.110). aspx

Http://blogs.msdn.com/b/swiss_dpe_team/archive/2008/02/08/iis-7-support-for-non-http-protocols.aspx

In order for IIS to support NET.TCP, you must first install the was (Windows Process Activation service), which is the Windows Processes activation service.

Open Control Panel-programs and features-turn Windows features on or off, install was,

After installation, you can go to the following service in the Services window: Windows Process Activation Service; NET.MSMQ Listener Adapter; Net.pipe Listener Adapter; Net.TCP Listener Adapter; Net.TCP Port Sharing Service. These few services. Determine if the net.tcp Listener Adapter and net.tcp Port sharing service have been started.

Similarly, it is also necessary to check whether WCF is enabled for Non-http support: NET Framework 3.5 and. NET Framework 4.5 each have their own support.

However, the services described above will only have one, and if only the. Net Framework 3.5 is enabled on the server, then these services can only use the 3.5 version of the DLL. If the. Net Framework version 4.5 is enabled, the 4.5 version is used regardless of whether the 3.5 version is enabled at the same time. You can use the SMSvcHost.exe of the service to determine the actual use of that version.

Configuration on IIS

In IIS, select your website, then click Bindings in the Action menu bar on the right, a "site bindings" window pops up, click Add, type Select Net.TCP

Select your site, click "Advanced Settings", pop up the form, add it manually in the "Enabled Protocols" column: Net.TCP. After this step, the site adds support for the NET.TCP protocol.

Example

The example is a new WCF template created with VS2012.

1      Public classService1:iservice12     {3          Public stringGetData (intvalue)4         {5             return string. Format ("You entered: {0}", value);6         }7 8          Publiccompositetype getdatausingdatacontract (compositetype composite)9         {Ten             if(Composite = =NULL) One             { A                 Throw NewArgumentNullException ("Composite"); -             } -             if(composite. Boolvalue) the             { -Composite. StringValue + ="Suffix"; -             } -             returnComposite; +         } -}


The following is the configuration of a WCF service that uses nettcpbinding.

<?XML version= "1.0"?><Configuration>  <appSettings>    <AddKey= "Aspnet:usetaskfriendlysynchronizationcontext"value= "true" />  </appSettings>  <system.web>    <compilationDebug= "true"targetframework= "4.5" />    <HttpRuntimetargetframework= "4.5"/>  </system.web>  <System.ServiceModel>    <Bindings>      <nettcpbinding>        <bindingname= "NewBinding1" />      </nettcpbinding>    </Bindings>    <Services>      <Servicename= "Nettcpsite.service1">        <Endpointbinding= "NetTcpBinding"bindingconfiguration= "NewBinding1"Contract= "Nettcpsite.iservice1" />        <EndpointAddress= "Mex"binding= "Mextcpbinding"bindingconfiguration=""Contract= "IMetadataExchange" />              </Service>    </Services>    <Behaviors>      <servicebehaviors>        <Behavior>          <!--to avoid disclosing metadata information, set the values below to false before deployment -          <Servicemetadatahttpgetenabled= "true"httpsgetenabled= "true"/>          <!--to receive exception details on faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -          <ServicedebugIncludeexceptiondetailinfaults= "false"/>        </Behavior>      </servicebehaviors>    </Behaviors>    <protocolmapping>        <Addbinding= "Basichttpsbinding"Scheme= "https" />    </protocolmapping>        <servicehostingenvironmentaspnetcompatibilityenabled= "true"multiplesitebindingsenabled= "true" />  </System.ServiceModel>  <system.webserver>    <Modulesrunallmanagedmodulesforallrequests= "true"/>    <Directorybrowseenabled= "true"/>  </system.webserver></Configuration>

The default configuration is optimized due to WCF 4.5. So, even without any configuration on the HTTP protocol, WCF service can access the WSDL by default in the browser.

If you want to access the WCF service for nettcpbinding, you need a client that also uses the NET.TCP protocol. Here, I used the VS 2012来 to finish.

The following is the configuration and code for the WCF client.

    class program    {        staticvoid Main (string[] args)        {            using  New  service1client ())            {                Console.WriteLine (proxy. GetData (ten));            }            Console.ReadLine ();        }    }

<?XML version= "1.0" encoding= "Utf-8"?><Configuration>    <Startup>         <supportedruntimeversion= "v4.0"SKU=". netframework,version=v4.5 " />    </Startup>    <System.ServiceModel>        <Bindings>            <nettcpbinding>                <bindingname= "Nettcpbinding_iservice1" />            </nettcpbinding>        </Bindings>        <Client>            <EndpointAddress= "Net.tcp://localhost/nettcpsite/service1.svc"binding= "NetTcpBinding"bindingconfiguration= "Nettcpbinding_iservice1"Contract= "Nettcpservice.iservice1"name= "Nettcpbinding_iservice1">                <Identity>                    <servicePrincipalNamevalue= "Host/lightweapon.fareast.corp.microsoft.com" />                </Identity>            </Endpoint>        </Client>    </System.ServiceModel></Configuration>

Let's take a closer look at which process is listening on the 808 ports occupied by net.tcp. From the above can be verified that the listening process on port 808 is 2060. This process ID is SMSvcHost.exe, which is the host process for the various services mentioned above.

WCF: How to host nettcpbinding on IIS7

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.