公司运用wcf比较多,所以自己研究一下寄宿做个笔记,wcf寄宿在控制台有两种方式
第一种,直接在控制台程序内添加wcf服务。
第二种分别添加控制台程序和wcf服务应用程序,前者引用后者,并在app.config添加<system.serviceModel>节点对应wcf
配置:(第一种方式配置会自动生成)
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="命名空间.服务名称">
<endpoint address="" binding="basicHttpBinding" contract="命名空间.服务名称">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfService1/Service1/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
.CS:
using (ServiceHost Host = new ServiceHost(typeof(Service1)))
{
Host.Opened += delegate
{
Console.WriteLine("服务已启动,按任意键停止!");
};
Host.Open();
Console.Read();
}
其中:ServiceHost需要添加对System.ServiceModel的using
浙公网安备 33010602011771号