Search

MessageInterceptor Example - Message references problem by pcibraro

Closed
as Other Help for as Other

0
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 202762
Opened: 9/14/2006 7:37:13 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
When a IChannelMessageInspector reads the received message and returns a reference to a new message, the InspectingChannelListener class still uses the old reference (An invalid one). As a result, WCF throws an exception when it tries to deserialize the request from that invalid reference.

This is for the september 2006 RC.
Details (expand)

Product Version

.NET Framework 3.0 Community Technology Preview June 2006
Product Language
English

Operating System
Windows XP Professional
Operating System Language
US English

Architecture
 

Priority
(1=blocking, 2=important, 3=nice to have)
 

Severity
(1=major functionality issue, 2=important functionality issue, 3=nice to have)
 

Steps to Reproduce
1. Create a new IChannelMessageInspector that changes the message reference to a new message. (The code for this message inspector is attached)
2. Configure the sample to use this new message inspector.
Actual Results
1. WCF throws an exception when it tries to read the message (Old reference)
Expected Results
1. WCF reads the new message, and executes the service.
Component Usage
(any information on your scenario that may help in investigating your issue)
 

How often does this happen?
 

Have you seen this problem in other versions?
 
File Attachments
1 attachments
Sign in to post a comment.
Posted by Microsoft on 9/14/2006 at 10:01 AM
Could you please clarify?
Posted by pcibraro on 9/14/2006 at 10:24 AM
The sample provided to drop the messages works fine, but, if I develop a new message inspector to read the message, WCF throws an exception. Take a look to this code,

public class ErrorServerInspector : IChannelMessageInspector
    {
        public ErrorServerInspector() { }

        public void OnSend(ref Message msg)
        {
            // do nothing
        }

        public void OnReceive(ref Message msg)
        {
            System.Xml.XmlDocument document = new System.Xml.XmlDocument();
            document.Load(msg.GetReaderAtBodyContents());

            // Create new message
            System.Xml.XmlNodeReader xmlReader = new System.Xml.XmlNodeReader(document.FirstChild);

            Message newMsg = Message.CreateMessage(msg.Version, null, xmlReader);

            // Preserve the headers of the original message
            newMsg.Headers.CopyHeadersFrom(msg);

            foreach (string propertyKey in msg.Properties.Keys)
                newMsg.Properties.Add(propertyKey, msg.Properties[propertyKey]);

            // Close the original message and return new message
            msg.Close();

            msg = newMsg;
        }

        public IChannelMessageInspector Clone()
        {
            return new ErrorServerInspector();
        }
    }

This sample does not work, because I am changing the message reference received as parameter.
Posted by Microsoft on 9/14/2006 at 2:48 PM
Look at the MessageInspector sample in the latest SDK for message transformation.

The "ref" in the sample you are looking at is somewhat misleading in that this particular sample inspects (and possibly tweaks) the message headers as most protocol channels (security excluded) do, and therefore isn't written to roundtrip the whole message.