【发布时间】:2014-12-08 14:34:46
【问题描述】:
我有一个由简单 WinForms 应用程序托管的 WCF 服务。在 Visual Studio 中,服务是通过内置的 WCF 服务主机启动的,一切正常。我现在想在我的主机应用中托管服务,但目前该服务没有运行。
服务应用:
ServiceHost host;
private void btnStart_Click(object sender, EventArgs e)
{
host = new ServiceHost(typeof(RegimesService));
host.Open();
lblStatus.Text = "Started...";
}
如果我关闭系统托盘中的 WCF 服务主机并单击我的开始按钮,代码会运行但服务永远不会启动?
这是我的服务主机应用配置:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="metaBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="diiRegimesService.RegimesService">
<endpoint address="" binding="basicHttpBinding" contract="diiRegimesService.IRegimesService"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8081" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
& 最后是我的服务项目 App.config:
<system.serviceModel>
<services>
<service name="diiRegimesService.RegimesService">
<endpoint address="" binding="basicHttpBinding" contract="diiRegimesService.IRegimesService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
当我从 cmd 行运行 netstat -a 时,端口 http://localhost:8080 没有在监听,所以就好像服务对象从未真正初始化过。我确定这是我的某个地方的配置中的一个简单错误,有什么想法吗?谢谢
【问题讨论】:
-
尝试以管理员身份运行宿主应用程序
标签: c# .net web-services wcf service