title: Why isn't my C# Soap Extension getting called?
body: <p>I have a C# Winforms client that called a Java web service.  The service gets invoked correctly and returns the expected results.</p>
  
  <p>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.</p>
  
  <p>Q: Any suggestions?  Any debugging tips?</p>
  
  <p>ClientTraceExtension.cs =></p>
  
  <pre><code>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;
              }
          }
          ...
  </code></pre>
  
  <p>app.config =></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
    &lt;system.web&gt;
      &lt;webServices&gt;
        &lt;soapExtensionTypes&gt;
          &lt;add 
             type="GITSearchClient.ClientTraceExtension, GITSearchClient" 
             priority="1" 
             group="0"/&gt;
        &lt;/soapExtensionTypes&gt;
      &lt;/webServices&gt;
    &lt;/system.web&gt;
    &lt;startup&gt;
      &lt;supportedRuntime version="v2.0.50727" sku="Client"/&gt;
    &lt;/startup&gt;
    &lt;system.serviceModel&gt;
          &lt;bindings&gt;
              &lt;basicHttpBinding&gt;
                 ...
  </code></pre>
  
  <p>Form1.cs =></p>
  
  <pre><code>    try
      {
          GitSearchServiceSoapClient webService = new GitSearchServiceSoapClient();
          RequestOptions requestOptions = new RequestOptions();
          resp = webService.GetOosData(requestOptions, edtGroupId2.Text, "2012");
          ...
  </code></pre>