SOAP EXTENSION PROBLEM, HELP ME

Hi all,
I had try to make a simple soap extension in C#, but there is an error during debug my program.

this is an error message :

An unhandled exception of type 'System.InvalidOperationException' occurred in system.web.services.dll
Additional information: Client found response content type of '', but expected 'text/xml'.

i implement this SOAP EXTENSION code with including ServerExtension.dll into client/bin and web service/bin and after
that i including with add reference that ServerExtension.dd on my client application and web service.

what error like that
is it important to configure priority in web.config

this is my code, maybe you can help me where is wrong code that make my program error

/// =====This is my SOAP Extension CODE===
using System;
using System.Text;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.IO;
using System.Net;

    // Define a SOAP Extension that traces the SOAP request and SOAP
    // response for the XML Web service method the SOAP extension is
    // applied to.

public class ServerExtension : SoapExtension
{
    Stream orgStream;
    Stream newStream;

    // When the SOAP extension is accessed for the first time, the XML Web
    // service method it is applied to is accessed to store the file
    // name passed in, using the corresponding SoapExtensionAttribute.   
    public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
    {       
        return 0;
    }

    // The SOAP extension was configured to run using a configuration file
    // instead of an attribute applied to a specific XML Web service
    // method.
    public override object GetInitializer(Type WebServiceType)
    {       
        return 0;
    }

    // Receive the file name stored by GetInitializer and store it in a
    // member variable for this specific instance.
    public override void Initialize(object initializer)
    {       
    }

    // Save the Stream representing the SOAP request or SOAP response into
    // a local memory buffer.
    public override Stream ChainStream( Stream stream )
    {
        orgStream = stream;
        newStream = new MemoryStream();
        return newStream;
    }

    //  If the SoapMessageStage is such that the SoapRequest or
    //  SoapResponse is still in the SOAP format to be sent or received,
    //  save it out to a file.
    public override void ProcessMessage(SoapMessage message)
    {
        switch (message.Stage)
        {
            case SoapMessageStage.BeforeSerialize:
                break;
            case SoapMessageStage.AfterSerialize:
                WriteOutput();
                break;
            case SoapMessageStage.BeforeDeserialize:
                WriteInput();
                break;
            case SoapMessageStage.AfterDeserialize:
                break;
            default:
                throw new Exception("invalid stage");
        }
    }

    public void WriteOutput()   
    {
        newStream.Position = 0;
        FileStream fs = new FileStream("C://server.log", FileMode.Append, FileAccess.Write);
        StreamWriter w = new StreamWriter(fs);

        w.WriteLine("After-Serialize");
        w.Flush();
        newStream.Position = 0;
        Copy(newStream,fs);
        fs.Close();

        newStream.Position = 0;
        Copy(newStream, orgStream);
        newStream.Position = 0;       
    }

    public void WriteInput()
    {
        Copy(orgStream, newStream);
        newStream.Position = 0;
        FileStream fs = new FileStream("C://server.log", FileMode.Append, FileAccess.Write);
        StreamWriter w = new StreamWriter(fs);
        w.WriteLine("Before_Deserialize");
        w.Flush();
        Copy(newStream, fs);
        fs.Close();
        newStream.Position = 0;       
    }

    void Copy(Stream from, Stream to)
    {
        TextReader reader = new StreamReader(from);
        TextWriter writer = new StreamWriter(to);
        writer.WriteLine(reader.ReadToEnd());
        writer.Flush();
    }
}

//====THIS IS MY SOAP EXTENSION ATTRIBUTE CODE ===
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.IO;
using System.Net;

[AttributeUsage(AttributeTargets.Method)]
public class ServerExtensionAttribute : SoapExtensionAttribute
{   
    private int priority=1;

    public override Type ExtensionType
    {
        get { return typeof(ServerExtension); }
    }

    public override int Priority
    {
        get { return priority; }
        set { priority = value; }
    }   
}


//===THIS IS MY SIMPLE WEB SERVICE====
        [WebMethod]       
    [ServerExtension()]   
        public string Hello()       
        {           
            return "HElLo There.... ";           
        }
       
//===THIS IS CLIENT CODE THAT INVOKE A SERVICE USING SOAP EXTENSION===
       
        private void button1_Click(object sender, System.EventArgs e)
        {
            Test_Client.localhost.Service1 ws = new Test_Client.localhost.Service1();
            textBox1.Text = ws.Hello();           
        }



Answer this question

SOAP EXTENSION PROBLEM, HELP ME

  • Action12

    Did anyone find a solution to this


  • Diamond.Yu

    I don't see any problems with the code, though I could have missed something. Could it be that the server sent back a response that wasn't XML A network trace would reveal the truth. You can enable network tracing within .NET as follows:

    http://msdn2.microsoft.com/en-us/library/ty48b824.aspx

    Daniel Roth



  • SOAP EXTENSION PROBLEM, HELP ME