简体   繁体   English

如何创建一个 web.config 文件来加载 SoapExtension?

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

I need to use a SoapExtension subclass (which I have created), but it seems that this class can only be initialized through a web.config file.我需要使用SoapExtension子类(我已经创建),但似乎只能通过web.config文件初始化此类。 I have read that it should be possible through app.config file, but I don't know how to do it that way.我读过它应该可以通过app.config文件实现,但我不知道该怎么做。

Problem : I don't have a web.config file in my project.问题:我的项目中没有web.config文件。

So I created one manually with the following content:所以我用以下内容手动创建了一个:

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

Despite breakpoints dispatched in each SoapExtension methods, nothing happens at runtime, it seems that it is never initialized nore called.尽管在每个 SoapExtension 方法中分派了断点,但在运行时没有任何反应,似乎它从未被初始化或调用。 My SoapService initializes ok, but without any extension.我的 SoapService 初始化正常,但没有任何扩展。

I guess that creating the web.config file manually may not be enough for it to be taken into account, so I am wondering how to properly configure my app to have a web.config file in order to use my SoapExtension.我想手动创建 web.config 文件可能不足以将其考虑在内,所以我想知道如何正确配置我的应用程序以具有 web.config 文件以便使用我的 SoapExtension。 It should go and initialize my class, processMessage, and chainStream stuff.它应该去初始化我的类、processMessage 和 chainStream 的东西。

Note : This is my first ever SoapExtension implementation, so I am not really sure about what I am doing.注意:这是我的第一个 SoapExtension 实现,所以我不太确定我在做什么。

I found out how to / where to insert the web.config content in the app.config file:我发现了如何/在何处插入 app.config 文件中的web.config内容:

I had to insert it after ApplicationSettings and userSettings elements.我必须在ApplicationSettingsuserSettings元素之后插入它。 This is the only place where it doesn't generate any error at runtime.这是它在运行时不会产生任何错误的唯一地方。 So no need for a web.config file, although I still would like to know how to configure the app, if someone has the answer.所以不需要 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 seems to be correctly initialized now, and the message filtering works fine.我的 SoapExtension 现在似乎已正确初始化,并且消息过滤工作正常。

Related to @soleshoe's comment I couldn't get my Unit tests (XUnit) to work, my App.config looked like this in the end.与@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