我使用 net.tcp 将 WCF 作为 Windows 服务托管。在启动服务时安装 Windows 服务后,我发现该服务已启动和停止。
错误说明为了向服务“MYService”添加端点,必须指定非空合同名称。在 System.ServiceModel.Description.ConfigLoader.LookupContract(String contractName, String serviceName)
我的 OnStart 函数如下
protected override void OnStart(string[] args)
{
try
{
if (myServiceHost != null)
{
myServiceHost.Close();
}
myServiceHost = new ServiceHost(typeof(MYservice));
myServiceHost.Open();
}
catch (Exception ex)
{
log.Error("ONStart", ex);
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
配置文件如下:
<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="10" />
<services>
<service behaviorConfiguration="myServiceBehavior"
name="myNamespace.myTestService">
<endpoint binding="netTcpBinding" bindingConfiguration="netTCPBindingConfig" contract="myNamespace.ServiceInterface.ImyTestService" />
<endpoint binding="mexTcpBinding" bindingConfiguration="" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://10.1.3.69:8523/TestService" />
</baseAddresses>
<timeouts closeTimeout="10:00:10" openTimeout="10:01:00" />
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)
在您的配置文件中,有:
<endpoint binding="netTcpBinding" bindingConfiguration="netTCPBindingConfig" contract="myNamespace.ServiceInterface.ISomeService" /> `
Run Code Online (Sandbox Code Playgroud)
取而代之的是ISomeService,您必须指定由 实现的任何接口MYService。
编辑
此外,mex 绑定必须指定一个合同,即 contract="IMetadataExchange"
再次编辑
为方便起见,您的 mex 绑定应如下所示:
<endpoint binding="mexTcpBinding" address="mex" bindingConfiguration="" contract="IMetadataExchange" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2362 次 |
| 最近记录: |