簡體   English   中英

通過.config文件設置自定義WCF綁定行為 - 為什么這不起作用?

[英]Setting custom WCF-binding behaviour via .config file - why doesn't this work?

我試圖在我的服務客戶端中插入自定義行為,遵循此處的示例

我似乎遵循所有步驟,但我得到一個ConfigurationErrorsException 有沒有比我更有經驗的人可以發現我做錯了什么?

這是整個app.config文件。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <endpointBehaviors>
                <behavior name="ClientLoggingEndpointBehaviour">
                    <myLoggerExtension />
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <extensions>
            <behaviorExtensions>
                <add name="myLoggerExtension"
                     type="ChatClient.ClientLoggingEndpointBehaviourExtension, ChatClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"/>
            </behaviorExtensions>
        </extensions>
        <bindings>
        </bindings>
        <client>
            <endpoint
                behaviorConfiguration="ClientLoggingEndpointBehaviour"
                name="ChatRoomClientEndpoint"
                address="http://localhost:8016/ChatRoom"
                binding="wsDualHttpBinding"
                contract="ChatRoomLib.IChatRoom"
                />
        </client>
    </system.serviceModel>
</configuration>

這是異常消息:

為system.serviceModel / behavior創建配置節處理程序時發生錯誤:無法將擴展元素“myLoggerExtension”添加到此元素。 驗證擴展是否已在system.serviceModel / extensions / behaviorExtensions的擴展集合中注冊。 參數名稱:element(C:\\ Documents and Settings \\ Andrew Shepherd \\ My Documents \\ Visual Studio 2008 \\ Projects \\ WcfPractice \\ ChatClient \\ bin \\ Debug \\ ChatClient.vshost.exe.config第5行)

我知道我已經正確地寫了對ClientLoggingEndpointBehaviourExtensionobject的引用,因為通過調試器我可以看到它被實例化了。

這是一個隨意的想法,但可能不是:反轉配置中元素的順序,因此擴展行為之前

-Oisin

事實證明,我沒有得到裝配合格的名稱。 程序集限定名稱對於.NET框架的加載是正確的,但是在匹配行為配置時,WCF框架會執行一個簡單的逐字符比較。

object, and wrote the AssemblyQualifiedName property to a local variable, which I then copy-and-pasted from the debug window into the .config file. 為了最終獲得確切的類型名稱,我編寫了代碼來創建對象的實例,並將AssemblyQualifiedName屬性寫入局部變量,然后將其從調試窗口復制並粘貼到.config文件中。

我不得不做所有這些被認為是WCF框架中的一個錯誤。 (見此鏈接 )顯然它已在.NET 4.0中修復。

另見本文。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM