2011-04-06 31 views
6

我需要使用SoapExtension子類(我已創建),但似乎只能通過「web.config」文件初始化此類(儘管我已經讀過應該可以通過「app.config」文件 - 但我不知道該怎麼做)。問題:我的項目中沒有web.config文件。所以,我用下面的內容創建一個手動:如何創建一個web.config文件來獲取SoapExtension加載?

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.web> 
    <webServices> 
     <soapExtensionTypes> 
     <add type="MyNameSpace.MySoapExtension,MyAssemblyFileName" priority="1"/> 
     </soapExtensionTypes> 
    </webServices> 
    </system.web> 
</configuration> 

儘管各的SoapExtension方法distpatched斷點,什麼都不會發生在運行時,它似乎永遠不會初始化諾雷得叫......(我SoapService初始化確定,但不任何延伸)。

我想手動創建web.config文件可能不足以考慮它,所以我想知道如何正確地配置我的應用程序有一個web.config文件,以便使用我的SoapExtension(它應該去初始化我的類,processMessage和chainStream的東西...)。

(注:這是我第一次的SoapExtension實現,我真的不知道有關我在做什麼)

回答

11

我發現瞭如何(或者實際上「阿凡達」)將在web.config內容app.config文件:

我必須在'ApplicationSettings'和'userSettings'之後插入它;這是它在運行時不會產生任何錯誤的唯一地方(所以不需要web.config文件 - 儘管如此,我仍然想知道如何配置應用程序,如果有人有答案...)。

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    </configSections> 
    <applicationSettings> 
    </applicationSettings> 
    <userSettings> 
    </userSettings> 
    <system.web> 
     <webServices> 
      <soapExtensionTypes> 
      <add type="MyNameSpace.MySoapExtension,MyAssemblyFileName" priority="1"/> 
      </soapExtensionTypes> 
     </webServices> 
    </system.web> 
    <system.serviceModel> 
     <bindings /> 
     <client /> 
    </system.serviceModel> 
</configuration> 

My SoapExtension似乎現在正確初始化,消息過濾工作正常。

0

與@ soleshoe的評論相關我不能讓我的單元測試(XUnit)工作,我的App.config最終看起來像這樣。

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    </configSections> 
    <system.web> 
    <webServices> 
     <soapExtensionTypes> 
     <add type="System.Common.SOAPExtensions.TraceExtension, System.Common" priority="1"/> 
     </soapExtensionTypes> 
    </webServices> 
    </system.web> 
</configuration> 
相關問題