繁体   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