[英]net.tcp, The socket connection was aborted
我創建了包含Windows服務(windowsservices.cs)的項目,並在該類(windowservices.cs)中添加了wcf合同和服務文件。 其app.config文件包含
<service behaviorConfiguration="WindowsService1.Service1Behavior"
name="AgentSvcImpl">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
name="nethttpendpoint" contract="IAgentWinService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="nethttpmetadataendpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8011/AgentSvcImpl" />
</baseAddresses>
</host>
</service>
在Windows服務onstart方法中,我輸入了以下代碼:
ServiceHost serviceHost = null;
if (serviceHost != null)
{
serviceHost.Close();
}
//Create a URI to serve as the base address
Uri httpUrl = new Uri("net.tcp://localhost:8011/AgentSvcImpl");
//Create ServiceHost
serviceHost = new ServiceHost(typeof(WindowsService1.AgentSvcImpl), httpUrl);
//Add a service endpoint
serviceHost.AddServiceEndpoint(typeof(WindowsService1.IAgentWinService), new NetTcpBinding(), "");
//Enable metadata exchange
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = false;
serviceHost.Description.Behaviors.Add(smb);
//Start the Service
serviceHost.Open();
當我在services.msc中啟動此服務時,它運行良好。 但是,當我嘗試添加服務引用時,出現以下錯誤。
元數據包含無法解析的引用:“ net.tcp:// localhost:8011 / AgentSvcImpl”。 套接字連接已中止。 這可能是由於處理您的消息時出錯,遠程主機超出了接收超時或潛在的網絡資源問題引起的。 本地套接字超時為“ 00:04:59.0054016”。 遠程主機強行關閉了現有連接。如果在當前解決方案中定義了服務,請嘗試構建解決方案並再次添加服務引用。
該如何解決呢?
可能的問題-沒有名稱空間的服務名稱和合同:
<service ... name="WindowsService1.AgentSvcImpl" ... contract="WindowsService1.IAgentWinService">
如果不是,請嘗試在WCF服務實現(AgentSvcImpl)類范圍內以一些非無限間隔(例如1秒)和空的OnTimer處理程序創建新的Timer。 並配置跟蹤以探索更多
看一下這篇文章: 如果我設置HttpGetEnabled = false會發生什么?
我猜你將需要激活該行為的HttpGetEnabled屬性:
smb.HttpGetEnabled = true;
希望會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.