4

I have problems with the configuration of a SoapExtension (not with the implementation). First of all, I've already read all these posts (among others), related in some way with SoapExtensions:

  1. Intercept SOAP messages from and to a web service at the client
  2. https://www.codeproject.com/Articles/34381/Efficient-Tracing-Using-SOAP-Extensions-in-NET
  3. https://social.msdn.microsoft.com/Forums/en-US/d8d6fe09-74be-4210-91bb-a8924a742e8c/how-to-log-soap-message-which-is-going-out-of-my-web-application?forum=ncl
  4. http://www.seanmcilvenna.com/2010/08/20/logging-full-soap-messages/
  5. How to create a web.config file to get SoapExtension loading?
  6. Intercept messages in a WCF Client
  7. https://msdn.microsoft.com/en-us/library/esw638yk(VS.85).aspx
  8. https://social.msdn.microsoft.com/Forums/en-US/1ba267b8-c08d-4c30-a1e1-792bac92fc87/soapextension-does-not-work-in-client-side?forum=netfxnetcom
  9. SoapExtension not loading

The scenario is as follow:

  • I'm consumming a 3rd party WS(SOAP) from a Library (dll) project: connectors.dll

  • In this project i've a web-reference to the 3rd party WS(SOAP). I generated the proxy with VS (adding a web-reference, and pointing to the wsdl).

  • In the other hand , I've a web-application (indeed is a REST-service), with a reference to a class (we could call it Connector-A) of connectors.dll

(until here, I call a rest service, over my REST-Service webapp, call the connector-A and this do a last call to proxy service of the 3rdParty. I receive a response, but it has an invalid character (0x1F at position 1), and this is why I'm trying to use SoapExtension -> to delete it before deserialization take place)

The last step, to configure: * add a reference (VS->Add Reference) in my REST-Service (webapp) to Backend.SoapExtnsions.dll and

  • register the soapExtension in web.config :

`

<system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxUrlLength="4000" />
    <authentication mode="None" />
    <webServices>
    <soapExtensionTypes>
        <add type="Backend.SoapExtensions.XmlCleanupSoapExtension, Backend.SoapExtensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=66269ab3fc862c8f" priority="1" group="0" />
        </soapExtensionTypes>
    </webServices>
    <globalization uiCulture="auto:es" culture="auto:es-ES" enableClientBasedCulture="true" />
</system.web>

`

When I call a rest-service that, at the end,it calls the WS-Soap i'm getting now a runtime exception, which makes me crazy:

The value of the property 'type' cannot be parsed. The error is: Could not load type 'Offidesk.Backend.SoapExtensions.XmlCleanupSoapExtension' from assembly 'Offidesk.Backend.SoapExtensions'.

I think I've tried all possible combinations for this line:

<add type="Backend.SoapExtensions.XmlCleanupSoapExtension, Backend.SoapExtensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=66269ab3fc862c8f" priority="1" group="0" />

  • with and without assembly name
  • with and without namespace
  • with and without Version, Culture and PublicToken
  • Group="0" and Group="High"

Actually, I'm completely frustated with this runtime exception. I though that perhaps the position of block inside could affect, but all my tries get the same exception...

Any idea??

thanks in advance.

Note: I also tried other tecniques to clean the server-response overriding the SoapHttpClientProtocol (in a extended class) method: GetReaderForMessage but don't work for me neither (don't know why).

EDIT

Finally the problem with the invalid character 0x1F was not such. I didn't realize that the response was coming compressed with gzip, and the proxy-client tried to parse a compressed response as XML, which obviously, was rising an exception at runtime.

However, I'm very insterested yet in knowing the reason why my web.config, with the soap extension, don't work (sooner or later we would need this configuration....so it's better to prevent).

salva_gl
  • 41
  • 5

2 Answers2

3

For Googlers like me who landed here, if your soap extension is a different project than the one using it, the expected format for "type" in your app/web.config is "namespace.class, project".

The error message is subtly different depending on what you're doing wrong.

If the error is "Could not load type 'MyType' from assembly 'System.Web.Webservices..." you don't have the second part after the comma--the project with the soap extension. It's wanting to find your class in System.Web.Webservices as the default, which of course is not where you have it.

If the error is simply "Could not load file or assembly 'MyProject' or one of its dependencies..." it means the second part after the comma is wrong rather than missing.

  • Make sure you actually have a reference to the soap project in the project where you're trying to use it.
  • Make sure you have it named correctly in your app/web.config. Don't assume it's just the first part of the namespace. In Solution Explorer go to the References of the project that has your app/web.config, right click the project you're trying to reference and see the Properties. The value you want to put in your app/web.config after the comma is in the "Identity" field.
Chad Hedgcock
  • 11,125
  • 3
  • 36
  • 44
1

I had a similar problem, but Chad Hedgcock's answer helped me out big time. My SopaExtension was in the same project with my WebService. When I tried to register it in web.config, I was getting all those errors, but when I moved the SoapExtension to a new project it simply started working (I only had to change the type field to include new project name).

jahu
  • 5,427
  • 3
  • 37
  • 64