Ori*_*ian 5 .net c# wcf windows-services
我有一个WCF服务器,可以作为服务或Windows窗体应用程序运行。当我将其作为Windows Forms应用程序运行时,可以通过客户端应用程序连接到它。但是,当我使用相同的代码将其作为服务运行时,无法连接到它。我已经确认该服务正在运行并且正在工作。以下是服务器的配置文件。
<system.serviceModel>
<services>
<service name="Cns.TrafficCopService.ManagementService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/TrafficCop/ManagementService" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="Cns.TrafficCopService.IManagementService" />
</service>
</services>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
及其托管代码(在OnStart之后100毫秒调用):
if (this.serviceHost != null)
{
this.serviceHost.Close();
}
this.serviceHost = new ServiceHost(typeof(ManagementService));
this.serviceHost.Open();
Run Code Online (Sandbox Code Playgroud)
和客户端的配置文件:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IManagementService" />
</wsHttpBinding>
</bindings>
<client>
<endpoint
address="http://localhost:8000/TrafficCop/ManagementService"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IManagementService"
contract="IManagementService"
name="WSHttpBinding_IManagementService">
</endpoint>
</client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
您可以发布托管该服务的其余代码吗?
启动服务的类应该继承自“ServiceBase”,并且应该实现“OnStart”和“OnStop”方法。这些方法由服务控制台调用来启动和停止服务进程,因此您的ServiceHost应该在这些方法中打开/关闭。只是想知道你是否没有这样做。
| 归档时间: |
|
| 查看次数: |
772 次 |
| 最近记录: |