This blog will show you how to host NetTcpBinding services in IIS.
1. Prepare the service code first.
Contract
namespacecontract{[ServiceContract] Public Interfaceicalculate {[OperationContract]DoubleADD (DoubleXDoubley); [OperationContract]DoubleSubtract (DoubleXDoubley); [OperationContract]DoubleMultiply (DoubleXDoubley); [OperationContract]DoubleDivide (DoubleXDoubley); }}
Service
namespaceservice{ Public classCalculate:icalculate { Public DoubleADD (DoubleXDoubley) {returnX +y; } Public DoubleDivide (DoubleXDoubley) {returnX-y; } Public DoubleMultiply (DoubleXDoubley) {returnX *y; } Public DoubleSubtract (DoubleXDoubley) {returnX/y; } }}
Web. config
<?XML version= "1.0" encoding= "Utf-8"?><Configuration> <Startup> <supportedruntimeversion= "v4.0"SKU=". netframework,version=v4.5.2 " /> </Startup> <System.ServiceModel> <Behaviors> <servicebehaviors> <Behaviorname= "Messagebehavior"> <Servicemetadata/> <ServicedebugIncludeexceptiondetailinfaults= "true"/> <DataContractSerializerMaxitemsinobjectgraph= "65535" /> </Behavior> </servicebehaviors> </Behaviors> <Services> <Servicename= "Service.calculate"behaviorconfiguration= "Messagebehavior"> <EndpointAddress= "Net.tcp://172.18.20.67:9998/calculateservice.svc"binding= "NetTcpBinding"Contract= "Contract.icalculate" /> <EndpointAddress= "Mex"binding= "Mextcpbinding"Contract= "IMetadataExchange"/> </Service> </Services> </System.ServiceModel></Configuration>
Svc
<Service= "service.calculate"%>
To configure the IIS environment, you need to turn non-http activation on,
Next, create a website to host the WCF service.
1). Add the NET.TCP protocol to the Advanced settings
2). Add port numbers that need to be open in the bindings of website, for example, to open 9998,
Finally, you need to enable access to ports in Windows Firewall.
So the entire configuration is complete.
How to host the WCF NetTcpBinding Service in IIS