我最欣赏linux的可定制性
so, 配置本身就是一种美
<system.serviceModel> <behaviors> <serviceBehaviors> <!--第一种元数据发布方式,好像只支持HTTP/HTTPS--> <behavior name="CalcServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> <services> <service name="ServiceLib.CalcService" behaviorConfiguration="CalcServiceBehavior"> <host> <baseAddresses> <add baseAddress="http://127.0.0.1:8888/Calc"/> </baseAddresses> </host> <endpoint address="" binding="wsHttpBinding" bindingConfiguration="" contract="ServiceLib.ICalcService" /> <!--第二种元数据发布方式,支持各种协议--> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> </system.serviceModel>
配置服务
同样的,代码就可以省略为以下内容
using (ServiceHost host = new ServiceHost(typeof(CalcService))) { host.Opened += (a, b) => Console.WriteLine("服务已开启"); host.Open(); Console.Read(); }
而,客户端无须做任何修改
时间: 2024-10-10 13:05:31