[英]Deploying WCF Service Host App without WCF Service Host?
I have a WCF service hosted by a simple WinForms app. 我有一个由简单WinForms应用程序托管的WCF服务。 In Visual Studio the service is started via the built in WCF Service Host & everything works fine. 在Visual Studio中,该服务通过内置的WCF服务主机启动,并且一切正常。 I now want to host the service in my host app but currently the service doesn't run. 我现在想在我的主机应用程序中托管该服务,但是当前该服务无法运行。
Service App: 服务应用程序:
ServiceHost host;
private void btnStart_Click(object sender, EventArgs e)
{
host = new ServiceHost(typeof(RegimesService));
host.Open();
lblStatus.Text = "Started...";
}
If I close WCF Service Host in the sys tray & click my start button, the code runs but the service never starts? 如果我关闭系统托盘中的WCF服务主机并单击“开始”按钮,则代码会运行,但服务永远不会启动?
Here's my Service Host App config: 这是我的服务主机应用程序配置:
<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>
& Finally my Service project App.config: 最后是我的服务项目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>
When I run netstat -a
from cmd line, the port http://localhost:8080
isn't listening so it's like the service object never actually gets initialized. 当我从cmd行运行netstat -a
,端口http://localhost:8080
没有监听,因此就像服务对象从未真正初始化过。 I'm sure it's a simple mistake in my configs somewhere, any ideas? 我确定这是我的某个地方的配置中的一个简单错误,有什么想法吗? Thanks 谢谢
端口8080是SQL Server的保留端口,您的服务App.config和Host App.config的基地址也具有不同的端口
Ok, used the WCF configuration wizard from Solution Explorer & tied the ServiceBehaviour
to the Service definition in the Host App's App.Config
& hey presto, everything is wired up & working! 好的,使用解决方案资源管理器中的WCF配置向导并将ServiceBehaviour
绑定到主机应用程序的App.Config
的服务定义,嘿,很简单,一切都已连接并正常工作! Thanks for your help @Akshay Choudhary. 感谢您的帮助@Akshay Choudhary。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.