标签:
<system.serviceModel> <services> <service name="MyNamespace.MyService"> <endpoint address="http://localhost:8000/MyService" binding="wsHttpBinding" contract="MyNamespace.IMyContract"/> </service> </services> </system.serviceModel>
<service name="MyService"> <endpoint address="http://localhost:8000/MyService" binding="wsHttpBinding" contract="IMyContract"/> <endpoint address="net.tcp://localhost:8001/MyService" binding="netTcpBinding" contract="IMyContract"/> <endpoint address="net.tcp://localhost:8002/MyService" binding="netTcpBinding" contract="IMyOtherContract"/> </service>
<system.serviceModel> <services> <service name="MyNamespace.MyService"> <host> <baseAddresses> <add baseAddress="net.tcp://localhost:8001/"/> <add baseAddress="http://localhost:8002/"/> </baseAddresses> </host> </service> </services> </system.serviceModel>
<system.serviceModel> <services> <service name="MyService"> <endpoint address="net.tcp://localhost:8000/MyService" bindingConfiguration="TransactionalTCP" binding="netTcpBinding" contract="IMyContract"/> <endpoint address="net.tcp://localhost:8001/MyService" bindingConfiguration="TransactionalTCP" binding="netTcpBinding" contract="IMyOtherContract"/> </service> </services> <bindings> <netTcpBinding> <binding name="TransactionalTCP" transactionFlow="true"/> </netTcpBinding> </bindings> </system.serviceModel>
应用到所有没有直接指定bindingConfiguration的EndPoint。一种绑定类型BasicHttpBinding/netTcpBinding/wsHttpBinding/...只能有一个默认配置
<netTcpBinding> <binding transactionFlow="true"/> <!--没有name属性--> </netTcpBinding>
ServiceHost host = new ServiceHost(typeof(MyService)); Binding wsBinding = new WSHttpBinding(); Binding tcpBinding = new NetTcpBinding(); host.AddServiceEndpoint(typeof(IMyContract),wsBinding, "http://localhost:8000/MyService"); host.AddServiceEndpoint(typeof(IMyContract),tcpBinding, "net.tcp://localhost:8001/MyService"); host.AddServiceEndpoint(typeof(IMyOtherContract),tcpBinding, "net.tcp://localhost:8002/MyService"); host.Open();
Uri tcpBaseAddress = new Uri("net.tcp://localhost:8000/"); ServiceHost host = new ServiceHost(typeof(MyService),tcpBaseAddress); Binding tcpBinding = new NetTcpBinding(); //Use base address as address host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,""); //Add relative address host.AddServiceEndpoint(typeof(IMyContract),tcpBinding,"MyService"); //Ignore base address host.AddServiceEndpoint(typeof(IMyContract),tcpBinding, "net.tcp://localhost:8001/MyService"); host.Open();
ServiceHost host = new ServiceHost(typeof(MyService)); //没有基地址 NetTcpBinding tcpBinding = new NetTcpBinding(); tcpBinding.TransactionFlow = true; //设置绑定属性 host.AddServiceEndpoint(typeof(IMyContract),tcpBinding, "net.tcp://localhost:8000/MyService"); host.Open();
使用下列构造函数,可以使用配置文件中的指定绑定配置来初始化绑定,或是使用空串来使用默认的绑定配置
public class NetTcpBinding : Binding,... { public NetTcpBinding(string configurationName); //More members }
标签:
原文地址:http://www.cnblogs.com/vicsmb/p/5244472.html