我目前正在將 winforms 應用程式遷移到 WPF,我需要做的最后一件事是遷移 WCF 服務
組態檔發送方:
<behaviors>
<serviceBehaviors>
<behavior name="NetPipeBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="True" httpHelpPageEnabled="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyLibrary.WcfServiceController.GuiController" behaviorConfiguration="NetPipeBehavior">
<endpoint address="" binding="netNamedPipeBinding" contract="MyLibrary.WcfServiceController.IGuiController" />
<endpoint address="mex" binding="mexNamedPipeBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/GUI-ORG/" />
</baseAddresses>
</host>
</service>
</services>
客戶端 :
<bindings>
<netNamedPipeBinding>
<binding name="NetNamedPipeBinding_IGuiController"/>
</netNamedPipeBinding>
</bindings>
<client>
<endpoint address="net.pipe://localhost/GUI-ORG/" binding="netNamedPipeBinding"
bindingConfiguration="NetNamedPipeBinding_IGuiController"
contract="GuiUpdaterReference.IGuiController" name="NetNamedPipeBinding_IGuiController">
</endpoint>
</client>
我有一個看起來像這樣的包裝器:
public class GuiControllerClientWrapper
{
private readonly LaunchType _launchType;
private readonly GuiUpdaterReference.IGuiController _gc;
public GuiControllerClientWrapper(LaunchType launchType)
{
_errorSent = false;
_launchType = launchType;
_gc = new GuiControllerClient();
if (launchType == LaunchType.Manual)
{
((GuiControllerClient)_gc).Open();
}
}
/* other functions */
}
呼叫 Open() 時發生例外: EndpointNotFoundException: There was no endpoint listening at "net.pipe://localhost/GUI-ORG" that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
內部例外如下: The pipe endpoint 'net.pipe://localhost/GUI-ORG' could not be found on your local machine
然后指向我的包裝器呼叫 open 函式的堆疊跟蹤
問題是,如果我在專案中添加舊的 winforms GUI 并重新安裝所有內容,它確實可以作業,發送訊息并且一切正常
我試過了
- 使用診斷,但它沒有給我任何我可以使用的資訊
- 更改地址
- 重新創建/更新服務參考
我錯過了什么?
uj5u.com熱心網友回復:
檢查“Net.Pipe Listener Adapter”服務是否在服務管理控制臺中運行。
Start Windows service -> Net.Pipe Listener Adapter service
沒有端點監聽 net.pipe
uj5u.com熱心網友回復:
發現了問題,即使例外可以幫助我,也不是 WCF 有問題
我有一個服務視窗,它每天運行一些代碼來檢查本地 AD 并執行一些操作我還有一個 GUI 允許我控制服務并手動開始處理
單擊按鈕時,客戶端上會啟動一個端點(通過進度條進行更新),但我不知道 WPF 在后臺作業者訪問主執行緒時會引發例外(WinForms 中并非如此)。
我的后臺作業人員會啟動,讀取資料源然后崩潰,直接進入RunWorkerCompleted關閉端點的事件
這就是 WCF 可以幫助我更多的地方:當我開始與后臺作業人員混在一起時,例外改變了它現在告訴我通信通道過早關閉
我的代碼現在使用對 UI 執行緒的安全訪問,這使通道在必要時保持活動狀態
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/375514.html
