簡體   English   中英

如何創建一個 web.config 文件來加載 SoapExtension?

[英]How to create a web.config file to get SoapExtension loading?

我需要使用SoapExtension子類(我已經創建),但似乎只能通過web.config文件初始化此類。 我讀過它應該可以通過app.config文件實現,但我不知道該怎么做。

問題:我的項目中沒有web.config文件。

所以我用以下內容手動創建了一個:

<?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 方法中分派了斷點,但在運行時沒有任何反應,似乎它從未被初始化或調用。 我的 SoapService 初始化正常,但沒有任何擴展。

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

注意:這是我的第一個 SoapExtension 實現,所以我不太確定我在做什么。

我發現了如何/在何處插入 app.config 文件中的web.config內容:

我必須在ApplicationSettingsuserSettings元素之后插入它。 這是它在運行時不會產生任何錯誤的唯一地方。 所以不需要 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>

我的 SoapExtension 現在似乎已正確初始化,並且消息過濾工作正常。

與@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>

暫無
暫無

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

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