WCF services hosted in IIS that are based on TCP bindings

Source: Internet
Author: User

WCF services hosted in IIS that are based on TCP bindings First, create a TCP binding based WCF Service 1, create a simple service specific code as follows service contract definition
namespace simpleservice{      //  Note: Using the rename command on the Refactor menu, you can change the interface name "Ihelloservice" in code and configuration files at the same time.        [ServiceContract]      publicinterface  ihelloservice      {          [ OperationContract]          string GetMessage (string  message);}      }
Service Specific method implementation
namespace simpleservice{    //  Note: Using the rename command on the Refactor menu, you can change the class name "HelloService" in code and configuration files at the same time. public    class  helloservice:ihelloservice    {         public  String GetMessage (string  message)        {            return'\ t  " + DateTime.Now;     }}}

To create the Svc file in the Web application, point to the service code
<%@ ServiceHost language="C #" debug="true" service="  simpleservice.helloservice" %>
The specific configuration file settings are as follows
<system.serviceModel> <services> <service name="Simpleservice.helloservice"behaviorconfiguration="httpgetenable"> <!--set the binding protocol to the TCP protocol---<endpoint address=""bindingconfiguration="nonesecurity"binding="nettcpbinding"contract="Simpleservice.ihelloservice"> </endpoint> <!--source data Access node-<endpoint address="Mex"binding="mexhttpbinding"contract="IMetadataExchange"> </endpoint> </service> </services> <bindings> <netTcpBinding> <!--allow port sharing so that other TCP-bound WCF services can also use 808 ports--<binding Name="nonesecurity"Portsharingenabled="true"> <!--Cancel Security verification--<security mode="None"> </security> </binding> </netTcpBinding> </bindings> <behaviors&      Gt <serviceBehaviors> <!--allows source data to be fetched over the HTTP protocol--<behavior Name="httpgetenable"> <servicemetadata httpgetenabled="true"/> <servicedebug includeexceptiondetailinfaults="true"/> </behavior> </serviceBehaviors> </behaviors> <!--enable multi-site bindings for easy access to IP addresses or domain names- <servicehostingenvironment aspnetcompatibilityenabled="true"Multiplesitebindingsenabled="true"> </serviceHostingEnvironment> </system.serviceModel> <system.webServer> <!--enable directory browsing for easy access to--&    Gt <directorybrowse enabled="true"/> </system.webServer>
The solution is specifically configured as follows

Second, set IIS to add non-HTTP protocol support open Control surface--Select large icon--programs and features--enable or disable Windows features--tick. net3.5 non-HTTP activation, if it is WIN8/8.1/10, you need to tick. All advanced features in net4.6

Create the Site directory that you want to host in IIS to point to the directory where the WCF Service web host resides

Add support for site non-HTTP bindings

Right-select Site-Edit bindings-Add--type Select net.tcp--binding information 808:*


Set up site Support NET.TCP protocol, right-click Site--Manage Website--Advanced settings--enabled protocols--Add net.tcp

Third, the final effect Access the site's Svc file in the browser, as

You can see that the net.tcp bindings are already in the source data

Invoking the service in WcfTestClient Add Service Address

Invoke Service

Service Client configuration file information

PostScript in official use, replace the host address in the client configuration file with the IP address of the host

WCF services hosted in IIS that are based on TCP bindings

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.