我试图在WindowsService中托管我的WCF服务。 感谢simplified configuration,无需担心配置文件内容。我找到了如何调整绑定配置(见下文)。但不是如何设置默认端口。
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<!-- No <service> tag is necessary. But how to define port? -->
<protocolMapping>
<add scheme="http" binding="basicHttpBinding"/>
</protocolMapping>
设置端口可以在代码中完成。但我想,打破配置文件的逻辑。我的目标是在这个WindowsService托管机制背后有一个非常简单的C#代码。所有其余的都在配置文件中。 简单如下:
protected override void OnStart(string[] args)
{
this._host?.Close();
this._host = new ServiceHost(typeof(IMyService));
this._host.Open();
}
我在互联网上找到的唯一有价值的资源是this MSDN documentation,它是在引入简化配置之前编写的。
如何在简化配置上下文中配置配置文件中的默认端口?