[英]Deploying WCF Service Host App without WCF Service Host?
我有一個由簡單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
沒有監聽,因此就像服務對象從未真正初始化過。 我確定這是我的某個地方的配置中的一個簡單錯誤,有什么想法嗎? 謝謝
端口8080是SQL Server的保留端口,您的服務App.config和Host App.config的基地址也具有不同的端口
好的,使用解決方案資源管理器中的WCF配置向導並將ServiceBehaviour
綁定到主機應用程序的App.Config
的服務定義,嘿,很簡單,一切都已連接並正常工作! 感謝您的幫助@Akshay Choudhary。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.