如何创建一个网络.配置文件获取SoapExtension加载



我需要使用一个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初始化ok,但是没有任何扩展。

我猜是创造网络。手动配置文件可能不足以让它被考虑在内,所以我想知道如何正确配置我的应用程序有一个web。配置文件,以便使用我的SoapExtension。它应该去初始化我的类,processMessage,和chainStream的东西。

注意:这是我的第一个SoapExtension实现,所以我真的不确定我在做什么。

我发现如何/在哪里插入web.config内容在app.config文件:

我必须在ApplicationSettingsuserSettings元素之后插入它。这是它在运行时不会产生任何错误的唯一地方。所以不需要网络。配置文件,虽然我仍然想知道如何配置应用程序,如果有人有答案。

<?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>

最新更新