我有一个由简单的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...";
}
如果我在sys托盘中关闭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
没有收听,因此它就像服务对象永远不会实际初始化一样。我确定在某些地方我的配置中有一个简单的错误,任何想法?谢谢
答案 0 :(得分:1)
端口8080是SQL Server的保留端口,您的服务App.config和Host App.config的基址也有不同的端口
答案 1 :(得分:0)
好的,使用了解决方案资源管理器中的WCF配置向导&amp;将ServiceBehaviour
绑定到主机应用App.Config
&amp;中的服务定义嘿presto,一切都有线和&amp;工作!感谢您的帮助@Akshay Choudhary。