locked
Routing Service, Custom Message Filters, and WsHttpBinding Problem. RRS feed

  • Question

  • I have a service contract with two string parameters.  I'm using the Routing Service with a custom message filter that examines one of these string parameters to determine if messages match the filter.  Everything works fine if the service endpoint exposed by the Routing Service the NetTcpBinding.  However, when I switch to the WsHttpBinding, the string parameters sometimes become corrupted in the MessageBuffer that is passed to the Match method of the custom message filter.  This corruption occurs when the string parameters have xml tags or newline characters.

    Stepping though the Match method shows that the MessageBuffer initially appears intact.  However a call to the MessageBuffer.CreateNavigator method returns an XPathNavigator object with corrupted parameters.  Is this a known issue and is there a workaround for this problem?

    Thank you.

    • Edited by mirwin101 Thursday, November 11, 2010 3:23 PM Typo
    Thursday, November 11, 2010 2:45 PM

All replies

  • Hi mirwin101,

    From your description, you're encountering some problem when try to route service request(through WCF 4 routing service) based on two string parameter(use wsHttpBinding). I think the problem is possibly due to the encoding convertion of the string parameter as you mentioned that you might embed some xml tags in it. Generally, it is not recommend that we use simple string parameter to transfer text that will contain xml or html like tags. If you want to transfer xml string, you should define a dedicated parameter of XmlElement or XElement type.  In addition, for string parameter that might contain special charaters(need encode or escape), you can try perform HtmlEncode on it(before assign them to the operation as parameter) to see whether it helps.

    #HttpUtility.HtmlEncode Method (String)
    http://msdn.microsoft.com/en-us/library/73z22y6h.aspx

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Mog Liang Thursday, November 18, 2010 8:40 AM
    • Unmarked as answer by mirwin101 Thursday, November 18, 2010 2:09 PM
    Monday, November 15, 2010 3:41 AM
  • Thanks for your reply.  WCF handles encoding of the XML tags in the strings automatically.  So there is no need to HtmlEncode them prior to sending a message.

    As I said before, the custom message filter works fine when using NetTcp.  Stepping through the custom message filter code shows that the MessageBuffer passed to the Match method has a MessageContentType of "application/soap+msbinsession1" when using NetTcp.

    When using WsHttp, the MessageBuffer passed to the Match method has a MessageContentType of "application/soap+xml; charset=utf-8".  It appears that either the MessageBuffer or XPathNavigator class has a bug that surfaces when dealing with that message content type.

    Certainly, the behaviour of the WCF Routing Service should not change when the endpoint encoding is switched from NetTcpBinding to WsHttpBinding.

    Mark

    • Edited by mirwin101 Thursday, November 18, 2010 2:08 PM typo
    Thursday, November 18, 2010 2:07 PM
  • Thanks for reply mirwin101,

    yes, the different content-type you see for NetTcpBinding and wsHttpBinding is due to the fact that NetTcpBinding by default use binary encoding for the message content while WSHttpBinding(like basicHttpBinding) use text encoding by default.  For test, you can try build a custom binding that use HttpTransportBindingElement and BinaryMessageEncoding binding element together to see whether it can works correctly. If so, the problem is possibly caused by the TextMessage encoding.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, November 19, 2010 3:07 AM