views:

29

answers:

1

I'm using Visual Studio 2010 and C# to write a web service that requires special handling that I'm solving by rolling my own SoapExtension. This SoapExtension is of course implementing the ProcessMessage method.

This is all fine, but for some reason this ProcessMessage is being called twice (two, 2 times) for each of the Stages of the SoapServerMessage and that is my problem. Any help with figuring out why this is and how I can make it only be called once (one, 1 time), would be highly appreciated.

BTW: I have found others on the web that have been having a similar problem, like this guy at mofeel.com, which indicates that he found the solution here at experts-exchange.com but I will not give out my creditcard for the solution. That is a principle. Can someone help me, please?

My ProcessMessage method looks like this:

public override void ProcessMessage(SoapMessage message)
{
    if (message is SoapServerMessage)
    {
        LogFile.WriteLogString(0, "-------------------");
        LogFile.WriteLogString(0, "message.Type:" + message.GetType().ToString());
        LogFile.WriteLogString(0, "message.Stage:" + message.Stage);
        LogFile.WriteLogString(0, "message.Stream.Length:" + message.Stream.Length);
        LogFile.WriteLogString(0, "message.Stream.Position:" + message.Stream.Position);
        LogFile.WriteLogString(0, "message.Exception:" + message.Exception);
        ProcessServerMessage(message);
    }
    else ProcessClientMessage(message);
}

...and when I make a single call to my web method I get a log looking like this:

7.7.2010 17:40:25: -------- Log file opened --------
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:BeforeDeserialize
7.7.2010 17:40:27: [0] message.Stream.Length:0
7.7.2010 17:40:27: [0] message.Stream.Position:0
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:BeforeDeserialize
7.7.2010 17:40:27: [0] message.Stream.Length:0
7.7.2010 17:40:27: [0] message.Stream.Position:0
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:AfterDeserialize
7.7.2010 17:40:27: [0] message.Stream.Length:330
7.7.2010 17:40:27: [0] message.Stream.Position:330
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:AfterDeserialize
7.7.2010 17:40:27: [0] message.Stream.Length:330
7.7.2010 17:40:27: [0] message.Stream.Position:330
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:BeforeSerialize
7.7.2010 17:40:27: [0] message.Stream.Length:0
7.7.2010 17:40:27: [0] message.Stream.Position:0
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:BeforeSerialize
7.7.2010 17:40:27: [0] message.Stream.Length:0
7.7.2010 17:40:27: [0] message.Stream.Position:0
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:AfterSerialize
7.7.2010 17:40:27: [0] message.Stream.Length:480
7.7.2010 17:40:27: [0] message.Stream.Position:480
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:AfterSerialize
7.7.2010 17:40:27: [0] message.Stream.Length:480
7.7.2010 17:40:27: [0] message.Stream.Position:480
7.7.2010 17:40:27: [0] message.Exception:

Notice how every message stage is being called twice?!?!?

+1  A: 

I see two possiblities here.

1- You have configured the soap extension in the web.config and you have a custom SoapExtensionAttribute that you applied to the web method.

This would essentially configure the SoapExtension twice and therefore it will run once because of the configuration in the web.config and a second time because of the attribute applied to the web method.

2- You have actually configured the soap extension twice in the web.config.

Chris Taylor
Thanks a million. You are right, I had it in the web.config file as well as applied the attribute.
Alfred B. Thordarson