The TCP-bound WCF Service is hosted in IIS.

Source: Internet
Author: User

The TCP-bound WCF Service is hosted in IIS.

 

Hosting TCP-bound WCF services in IIS 1. Create a TCP-bound-based WCF Service 1. Create a simple service code as follows: Service Contract Definition
Namespace SimpleService {// Note: You can use the "RENAME" command on the "refactoring" menu to change the Interface Name "IHelloService" in the Code and configuration file at the same time ". [ServiceContract] public interface IHelloService {[OperationContract] string GetMessage (string message );}}
Service implementation
Namespace SimpleService {// Note: You can use the "RENAME" command on the "refactoring" menu to change the class name "HelloService" in the Code and configuration file at the same time ". Public class HelloService: IHelloService {public string GetMessage (string message) {return message + "\ t" + DateTime. Now ;}}}

 

Create an SVC file in the Web application to 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 TCP --> <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 to allow other TCP-bound-based WCF services to use port 808 --> <binding name = "NoneSecurity" portSharingEnabled = "true"> <! -- Cancel security verification --> <security mode = "None"> </security> </binding> </netTcpBinding> </bindings> <behaviors> <serviceBehaviors> <! -- Allow source data to be obtained through http --> <behavior name = "HttpGetEnable"> <serviceMetadata httpGetEnabled = "true"/> <serviceDebug includeExceptionDetailInFaults = "true"/> </behavior> </serviceBehaviors> </behaviors> <! -- Enable multi-site binding for easy access using IP addresses or domain names --> <serviceHostingEnvironment aspNetCompatibilityEnabled = "true" multipleSiteBindingsEnabled = "true"> </serviceHostingEnvironment> </system. serviceModel> <system. webServer> <! -- Enable directory browsing for ease of use --> <directoryBrowse enabled = "true"/> </system. webServer>
The specific configuration of the solution is as follows:

2. Set IIS to add non-Http protocol support to open the control plane -- select the big icon -- program and function -- enable or disable windows function -- select. non-Http activation for net3.5. If it is win8, 8.1, or 10, you need to check it. all advanced functions of net4.6

In IIS, create the site directory to be hosted to point to the directory where the WCF Service Web host is located.

Added support for site non-HTTP binding

Right-click a site, select Edit binding, add type, and select net. tcp. The binding information is 808 :*


Set the site to support the net. tcp protocol, right-click the site, choose website management> Advanced Settings> enabled protocols, and add net. tcp.

Iii. Final Results Access the site's SVC file in the browser. The effect is as follows:

Net. tcp binding can be seen in the source data.

Call the service in WCFTestClient Add service address

Call Service

Service client configuration file information

Note: in actual use, replace the host address in the client configuration file with the Host IP address.

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.