none
Unable to recreate a message in AfterReceiveReply() due to a prefix in type attribute value RRS feed

  • Question

  • Message is recreated in the following manner:

    XmlDictionaryReader xdr = reply.GetReaderAtBodyContents();
    XElement xeBody = (XElement)XElement.ReadFrom(xdr);
    
    //Do some inspection work
    ...
    Message newMessage = Message.CreateMessage(reply.Version, null, xeBody.CreateReader());
    newMessage.Headers.CopyHeadersFrom(reply.Headers);
    newMessage.Properties.CopyProperties(reply.Properties);
    reply = newMessage;
    
    

    This works fine except when the original message contains something like Type="xx:TypeFoo".

    I noticed the XmlDictionaryReader replaces all prefixes with namespaces at nodes.

    For example, the following original tag

    <xx:ElementFoo token="tokenFoo">

    is changed to

    <ElementFoo token="tokenFoo" xmlns="http://www.foo.org/schema">

    However, the following tag

    <ElementFoo2 Name="MyFoo" Type="xx:FooType">

    remains the same.  In other words, the prefix "xx" stays there. This makes the recreated message malformed and generates an exception.  The message works fine if it is not recreated in the inspector. 

    I guess I could remove the Type attribute, but what is the right way to handle prefixes in attribute values? 

    BTW, this is a Silverlight Windows Phone app. 


    Hong

    Thursday, October 9, 2014 4:05 PM

All replies

  • I have been suggested to post this question here at Windows Phone forum.

    Message is recreated in the following manner:

    XmlDictionaryReader xdr = reply.GetReaderAtBodyContents();
    XElement xeBody = (XElement)XElement.ReadFrom(xdr);
    
    //Do some inspection work
    ...
    Message newMessage = Message.CreateMessage(reply.Version, null, xeBody.CreateReader());
    newMessage.Headers.CopyHeadersFrom(reply.Headers);
    newMessage.Properties.CopyProperties(reply.Properties);
    reply = newMessage;

    This works fine except when the original message contains something like Type="xx:TypeFoo".

    I noticed the XmlDictionaryReader replaces all prefixes with namespaces at nodes.

    For example, the following original tag

    <xx:ElementFoo token="tokenFoo">

    is changed to

    <ElementFoo token="tokenFoo" xmlns="http://www.foo.org/schema">

    However, the following tag

    <ElementFoo2 Name="MyFoo" Type="xx:FooType">

    remains the same.  In other words, the prefix "xx" stays there. This makes the recreated message malformed and generates an exception.  The message works fine if it is not recreated in the inspector. 

    I guess I could remove the Type attribute, but what is the right way to handle prefixes in attribute values? 

    BTW, this is a Silverlight Windows Phone app.


    Hong


    • Merged by Yang,Chenfei Tuesday, October 14, 2014 8:40 AM Duplicate Issue
    • Edited by Hong (MA, USA) Tuesday, October 14, 2014 11:42 AM
    Friday, October 10, 2014 2:40 PM
  • Hi Hong,

    I am not sure i have understood your issue. If you want to use xx prefix. You should import the namespace first in XAML Page.

    Monday, October 13, 2014 7:47 AM
  • I am sorry for the confusion. I posted the question to the WCF originally, then copied it here per a suggestion. I should have clarified it by stating this is related to web services, and not related to XAML when I posted the question on this forum.

    Thank you for reminding me this.


    Hong


    Monday, October 13, 2014 11:36 AM
  • Hi Hong,

    Thanks for posting on MSDN forum.

    I consult this issue with WCF experts. It’s a Web Services issue. I will help you to merge the thread to the original one, where you can contact Web Services experts. Thanks for your understanding!

    Best Regards,

    Jimmy Yang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 14, 2014 8:38 AM
  • Thanks a lot, Jimmy.

    Hong

    Tuesday, October 14, 2014 11:41 AM