[英]Host a WCF Service in a Windows Service but endpoint not found
我有一個dulpex WCF服務,該服務托管在Windows服務中。 我通過InstallUtil.exe從命令行安裝Windows Service,然后從服務管理面板啟動該服務。 現在該測試WCF了。 因此,我將一個新的控制台項目添加為客戶端,下一步是向該項目添加Web引用。 但是我得到一個錯誤:
There was an error downloading `http://localhost:8733/KeyValueService/_vti_bin/ListData.svc/$metadata`.
Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:8733
Metadata contains a reference that cannot be resolved: `http://localhost:8733/KeyValueService`.
服務項目中的app.config具有:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="VoiceApp.KeyValueService">
<endpoint address="http://localhost:8733/KeyValueService/" binding="wsDualHttpBinding" contract="VoiceApp.IService1" />
<endpoint address="http://localhost:8733/KeyValueService/mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
</basicHttpBinding>
</bindings>
<client>
</client>
我通過Metatata Exchange Endpoint Blog進行了配置,但這無濟於事。
在Windows服務中,我們還有:
protected override void OnStart(string[] args)
{
if (serviceHost != null)
{
serviceHost.Close();
}
serviceHost = new ServiceHost(typeof(KeyValueService));
serviceHost.Open();
MyApplication.Start(); // a long running code...
}
更新:
我的步驟是創建Windows服務項目,然后添加WCF服務。
我知道這是一篇舊文章,但是我發現,如果將“ localhost”替換為端點的真實IP地址,就可以解決此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.