views:

249

answers:

0

I'm creating a custom IDispatchOperationSelector to support a Java client calling a WCF service - this Java client does not send the SoapAction header, so I need to select the operation based on the body of the message. Below is the custom SelectOperation method. It works just fine when the debugger is NOT attached - however, when it is attached I get an error: "There was an error in deserializing one of the headers in message. Please see InnerException for more details." The InnerException message is: "Message is closed." It's acting like it is not using the "newMessage" message. However, again, this exception is thrown only when the VS debugger is attached. Any ideas?

public string SelectOperation(ref Message message)
{
    var buffer = message.CreateBufferedCopy(int.MaxValue);

    var newMessage = buffer.CreateMessage();

    using (new DisposableAction(() => buffer.Close()))
    using (var copy = buffer.CreateMessage())
    using (var reader = copy.GetReaderAtBodyContents())
    {
        string operationName = reader.LocalName;

        copy.Close();
        message.Close();
        message = newMessage;
        return operationName;
    }
}