Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I have read that it should be possible through app.config file, but I don't know how to do it that way.

Problem: I don't have a web.config file in my project.

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. My SoapService initializes ok, but without any extension.

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. It should go and initialize my class, processMessage, and chainStream stuff.

Note: This is my first ever SoapExtension implementation, so I am not really sure about what I am doing.

like image 996
soleshoe Avatar asked Apr 06 '11 08:04

soleshoe


2 Answers

I found out how to / where to insert the web.config content in the app.config file:

I had to insert it after ApplicationSettings and userSettings elements. 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.

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

like image 107
soleshoe Avatar answered Oct 21 '22 18:10

soleshoe


Related to @soleshoe's comment I couldn't get my Unit tests (XUnit) to work, my App.config looked like this in the end.

<?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>
like image 45
Sarkie Avatar answered Oct 21 '22 17:10

Sarkie