步驟 2:分類配接器和連接屬性
完成時間: 30 分鐘
在此步驟中,您會更新 EchoAdapterBindingElement 和 EchoAdapterBindingElementExtensionElement 類別,以將類別指派給配接器和連線屬性。 如此一來,屬性會依 [新增配接器服務參考外掛程式] 和 [取用配接器服務增益集] 工具中的類別,以邏輯方式分組。 例如,如果您希望 Application、 EnableAuthentication和 Hostname 屬性出現在 [ 連線 ] 類別之下,如下所示,您必須將 [連線] 類別指派給每個應用程式、EnableAuthentication 和 Hostname 屬性。
同樣地,如果您希望 InboundFileFilter 和 InboundFleSystemWatcherFolder 屬性出現在 [ 輸入 ] 類別之下,如下所示,您必須將 [輸入] 類別指派給每個類別。 如果您想要 讓 Count 和 EnableConnectionPooling 出現在 Misc 類別之下,您必須將 Misc 類別指派給每個類別。
請記住,您可以使用您選擇的任何類別名稱來指派屬性。 在此範例中,由於 EnableConnnectionPooling 屬性不屬於任何其他類別,因此我們會將其分類為 Misc (Othereous) 。 如同 InboundFileFilter 屬性,因為它會在範例內的輸入處理期間使用,所以更適合將 Inbound 指派給 屬性,而不是 [其他]。 以下是回應配接器的完整自訂屬性分類。
屬性 | 類別 |
---|---|
InboundFileFilter | 連入 |
InboundFileSystemWatcherFolder | 連入 |
Count | 其他 |
EnableConnectionPooling | 其他 |
應用程式 | 連線 |
EnableAuthentication | 連線 |
Hostname (主機名稱) | 連線 |
EchoInUpperCase | 格式 |
除了這些變更之外,您也會修改 EchoAdapterHandlerBase的 Dispose 方法。
如需回應配接器所公開的配接器屬性,請參閱 教學課程 1:開發 Echo 配接器中的配接器屬性一節。
必要條件
開始此步驟之前,您必須完成 步驟 1:使用 WCF LOB 配接器開發精靈建立 Echo 配接器專案。 您也應該熟悉 System.ServiceModel.Configuration.BindingElementExtensionElement
和 System.ServiceModel.Configuration.StandardBindingElement
類別。
更新 EchoAdapterHandlerBase Dispose 方法
在方案總管中,按兩下EchoAdapterHandlerBase.cs檔案。
從 Dispose 方法中移除下列語句:
throw new NotImplementedException("The method or operation is not implemented.");
修訂的方法看起來應該類似下列:
protected virtual void Dispose(bool disposing) { // //TODO: Implement Dispose. Override this method in respective Handler classes // }
更新 Adapter 屬性類別
在方案總管中,按兩下EchoAdapterBindingElement.cs檔案。
在 Visual Studio 編輯器中,展開 [自訂產生的屬性] 區域。
若要將 Misc 類別指派給 Count 屬性,請將下列單一語句新增至 Count 實作的開頭。
[System.ComponentModel.Category("")]
Count實作現在應該符合下列專案:
[System.ComponentModel.Category("")] [System.Configuration.ConfigurationProperty("count", DefaultValue = 5)] public int Count { get { return ((int)(base["Count"])); } set { base["Count"] = value; } }
若要將 Misc 類別指派給 EnableConnectionPooling 屬性,請將下列單一語句新增至 EnableConnectionPooling 實 作的開頭。
[System.ComponentModel.Category("")]
若要將 Inbound 類別指派給 InboundFileFilter 屬性,請將下列單一語句新增至 InboundFileFilter 實作的開頭。
[System.ComponentModel.Category("Inbound")]
若要將 Inbound categoryto inboundFleSystemWatcherFolder 屬性指派給 InboundFleSystemWatcherFolder 屬性,請將下列單一語句新增至 inboundFleSystemWatcherFolder 實作的開頭。
[System.ComponentModel.Category("Inbound")]
檢查以確定 自訂產生的屬性 區域中的程式碼符合下列專案:
[System.ComponentModel.Category("")] [System.Configuration.ConfigurationProperty("count", DefaultValue = 5)] public int Count { get { return ((int)(base["Count"])); } set { base["Count"] = value; } } [System.ComponentModel.Category("")] [System.Configuration.ConfigurationProperty("enableConnectionPooling", DefaultValue = true)] public bool EnableConnectionPooling { get { return ((bool)(base["EnableConnectionPooling"])); } set { base["EnableConnectionPooling"] = value; } } [System.ComponentModel.Category("Inbound")] [System.Configuration.ConfigurationProperty("inboundFileFilter", DefaultValue = "*.txt")] public string InboundFileFilter { get { return ((string)(base["InboundFileFilter"])); } set { base["InboundFileFilter"] = value; } } [System.ComponentModel.Category("Inbound")] [System.Configuration.ConfigurationProperty("inboundFileSystemWatcherFolder", DefaultValue = "{InboundFileSystemWatcherFolder}")] public string InboundFileSystemWatcherFolder { get { return ((string)(base["InboundFileSystemWatcherFolder"])); } set { base["InboundFileSystemWatcherFolder"] = value; } } #endregion Custom Generated Properties
更新連線屬性
在方案總管中,按兩下EchoAdapterConnectionUri.cs檔案。
在 Visual Studio 編輯器中,展開 [自訂產生的屬性] 區域。
若要將 Format 類別指派給 EchoInUpperCase 屬性,請將下列單一語句新增至 EchoInUpperCase 實作的開頭。
[System.ComponentModel.Category("Format")]
若要將 Connection 類別指派給 Hostname 屬性,請將下列單一語句新增至 Hostname 實作的開頭。
[System.ComponentModel.Category("Connection")]
若要將 Connection 類別指派給 Application 屬性,請將下列單一語句新增至 Application 實作的開頭。
[System.ComponentModel.Category("Connection")]
若要指派 Connection categoryto EnableAuthentication 屬性,請將下列單一語句新增至 EnableAuthentication 實作 的開頭。
[System.ComponentModel.Category("Connection")]
檢查以確定 自訂產生的屬性 區域中的程式碼符合下列專案:
#region Custom Generated Properties [System.ComponentModel.Category("Format")] public bool EchoInUpperCase { get { return this.echoInUpperCase; } set { this.echoInUpperCase = value; } } [System.ComponentModel.Category("Connection")] public string Hostname { get { return this.hostname; } set { this.hostname = value; } } [System.ComponentModel.Category("Connection")] public string Application { get { return this.application; } set { this.application = value; } } [System.ComponentModel.Category("Connection")] public bool EnableAuthentication { get { return this.enableAuthentication; } set { this.enableAuthentication = value; } } #endregion Custom Generated Properties
在 Visual Studio 的 [ 檔案] 功能表中,按一下 [ 全部儲存]。
注意
您應該已經儲存您的工作結果。 此時您可以安全地關閉 Visual Studio,或移至下一個步驟 :步驟 3:實作 Echo 配接器的連線。
我剛做了什麼?
您剛剛更新類別,以將類別指派給回應配接器所公開的每個配接器和連接屬性。
後續步驟
您可以實作連線、中繼資料流覽、搜尋和解析功能,以及輸出訊息交換。 最後,您會建置和部署回應配接器。