11

I have a C# Winforms client that called a Java web service. The service gets invoked correctly and returns the expected results.

I've been trying until I'm blue in the face to add a Soap Extension. It compiles correctly, I have every reason to believe it's getting registered ... but it never gets called. I tried modifying app.config; I tried calling "wss.SoapExtensionTypes.Add(soapInterceptor)": same thing. My SoapException's "Initalize()" and "ProcessMessage()" functions are simply never getting called.

Q: Any suggestions? Any debugging tips?

ClientTraceExtension.cs =>

using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Services.Configuration;
using System.IO;
using System.Net;
using System.Reflection;
using System.Security.Permissions;
using GITSearchClient.ServiceReference1;

/*
 * REFERENCE:
 * http://msdn.microsoft.com/en-US/library/system.web.services.protocols.soapextension%28v=vs.90%29.aspx
 */
namespace GITSearchClient
{
    public class ClientTraceExtension : SoapExtension
    {
        private Stream oldStream;
        private Stream newStream;
        private string filename = "c:\\temp\\soap_result.txt";

        // Custom SoapExtension must override: ChainStream, GetInitializer()x2, Initialize() and ProcessMessage()
        public override Stream ChainStream(Stream stream)
        {
            oldStream = stream;
            newStream = new MemoryStream();
            return newStream;
        }

        public override object GetInitializer(Type WebServiceType)
        {
            // filename = "C:\\temp\\soap_" + WebServiceType.FullName + ".txt";
            //return filename;
            return null;
        }

        public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
        {
            //return filename;
            return null;
        }

        public override void Initialize(object initializer)
        {
            // filename = (string)initializer;
        }

        public override void ProcessMessage(SoapMessage message)
        {
            //int i = 0;
            //int j = 1 / i;  // DEBUG: Stop here
            switch (message.Stage)
            {
                case SoapMessageStage.BeforeSerialize:
                    break;
                case SoapMessageStage.AfterSerialize:
                    WriteOutput(message);
                    break;
                case SoapMessageStage.BeforeDeserialize:
                    WriteInput(message);
                    break;
                case SoapMessageStage.AfterDeserialize:
                    break;
            }
        }
        ...

app.config =>

<?xml version="1.0"?>
<configuration>
  <system.web>
    <webServices>
      <soapExtensionTypes>
        <add 
           type="GITSearchClient.ClientTraceExtension, GITSearchClient" 
           priority="1" 
           group="0"/>
      </soapExtensionTypes>
    </webServices>
  </system.web>
  <startup>
    <supportedRuntime version="v2.0.50727" sku="Client"/>
  </startup>
  <system.serviceModel>
        <bindings>
            <basicHttpBinding>
               ...

Form1.cs =>

    try
    {
        GitSearchServiceSoapClient webService = new GitSearchServiceSoapClient();
        RequestOptions requestOptions = new RequestOptions();
        resp = webService.GetOosData(requestOptions, edtGroupId2.Text, "2012");
        ...
paulsm4
  • 114,292
  • 17
  • 138
  • 190

1 Answers1

7

I think you are mixing old and new here, i.e ASMX web services with WCF, see this question for a similar issue. Look at the answers by John.

Community
  • 1
  • 1
Tommy Grovnes
  • 4,126
  • 2
  • 25
  • 40
  • Hi - I'm using MSVS 2010 to create my WinForm app. There's no .asmx or WCF in the mix at all - it *should* be pure, platform/language/version agnostic SOAP. *HOWEVER* .... it certainly smells like it could be a ".Net version problem". I already backed my runtime down from .Net 4.0 (the default) to .Net 3.5/Client profile. Perhaps it would magically start working if I backed it down further, to .Net 2.0. Or substituted the new `IClientMessageInspector` your link mentions. Thanx for the tip - I'll keep you posted. – paulsm4 Jan 05 '13 at 19:28
  • I'm thinking the SoapExtension is ASMX tech and you are using a WCF client (based on your config), you probably should do IClientMessageInspector instead, it's WCF. – Tommy Grovnes Jan 05 '13 at 20:09
  • 3
    Yup - you're absolutely correct. The problem occurred when MSVS 2010 did a "create service reference" from my WSDL. Older versions of MSVS created a "Web Reference", using .Net 2.0/System.Web.Services technology. MSVS 2008 and higher creates a "Service Reference", using .Net 3.x/System.ServiceModel/WCF technology. And the WCF auto-generated "plumbing" doesn't recognize .Net 2.0 "SoapExtensions". The solution is to use IClientMessageInspector instead of a SoapExtension. Here's another link: http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/1ba267b8-c08d-4c30-a1e1-792bac92fc87 – paulsm4 Jan 05 '13 at 20:51
  • I'n in the same situation as the OP, but I would like to add something. The SoapExtension can still be attached, and the initializer is called when the client is instatiated, it's just the ProcessMessage function that is never called. So I created an IMessageInspector to replace it and attached it at the transport level - it works perfectly, but it doesn't give you access to the raw incoming data stream. The XML has been validated before you get to see it. That's not an option for me, if the webservice (as it happens) sends an HTML error page instead of XML, I want to get that HTML. – Luc VdV Sep 28 '18 at 05:51
  • BTW, re previous comment: I'm working on a .net 4.7 replacement for an old .net 2.0 client. I thought it would be easy :( – Luc VdV Sep 28 '18 at 05:56