none
WCF various binding and their corresponding message encoding RRS feed

  • Question

  • 1) wcf has many binding type like

    a) basichttp binding

    b) wshttp binding

    c) dualhttp binding

    d) tcp binding

    e) msmq binding

    f) NetNamedPipe binding

    each binding has different message encoding like text/xml/binary etc

    so i like to know in which binding text is used a message encoding again when xml is used as message encoding and when binary data is used as message encoding. please explain it for all binding and their corresponding message encoding.

    2) when any wcf service has binary message encoding then how jquery can consume that wcf service and parse it. i guess in case of tcp binding the message encoding will be always binary then how client can call wcf service by jquery & parse it?

    3) when any company will be planning to develop any wcf service which can be consume any technology like java,vb6,.net,php,python etc then what will be the binding they should follow as a result any client can consume it. is it basichttp if yes then why..... how could they provide tight security for basichttp binding.

    4) what are the new bindings has been released now with wcf latest version. i need their details. so just redirect me to right page from where i can learn more about new wcf binding like web socket. what message encoding is used for wcf web socket binding?

    please discuss my all points in details. thanks



    • Edited by Mou_kolkata Tuesday, February 4, 2014 7:06 PM
    Tuesday, February 4, 2014 7:03 PM

Answers

  • For .NET application, as long as the text/chars have been loaded into String object, they have been converted to UTF-16 unicode chars(in memory). it is only when you convert string into raw bytes do you need to specify the text encoding(such as utf-8, iso-8859-1, gb2312...).

    For your scenario, the WCF use the <textMessageEncoding> binding element to control the underlying character encoding of SOAP TEXT based (or plain xml) service messages, and by default utf-8 should be used since it can cover all the various characters(within Unicode rage).  Therefore, if you have WCF client that need to connect a JAVA webservice which return message in other text/char encoding, you should change the encoding of the textMessageEncoding binding element of the WCF client.  For WCF client configuration, if you are using customBinding, you can directly define the <textMessageEncoding> element, while if you are using some system binding (like basicHttpBinding or wsHttpBinding, you can use the property on <binding> element to configure the textEncoding. e.g.
     <bindings>
       <basicHttpBinding>
        <binding name="utf_8_binding" textEncoding="utf-8" ></binding>
       </basicHttpBinding>
    
       <customBinding>
        <binding name="custombinding1">
         <textMessageEncoding writeEncoding="utf-8" />
         <httpTransport />
        </binding>
       </customBinding>
      </bindings>
    

    so you don't need to manually do the encoding convertion in code. Just setup a proper endpoint with the correctly text encoding (set for the binding) that is corresponding to the service side.

     

    • Marked as answer by Mou_kolkata Sunday, February 9, 2014 8:53 AM
    Friday, February 7, 2014 11:30 AM

All replies

  • For .NET application, as long as the text/chars have been loaded into String object, they have been converted to UTF-16 unicode chars(in memory). it is only when you convert string into raw bytes do you need to specify the text encoding(such as utf-8, iso-8859-1, gb2312...).

    For your scenario, the WCF use the <textMessageEncoding> binding element to control the underlying character encoding of SOAP TEXT based (or plain xml) service messages, and by default utf-8 should be used since it can cover all the various characters(within Unicode rage).  Therefore, if you have WCF client that need to connect a JAVA webservice which return message in other text/char encoding, you should change the encoding of the textMessageEncoding binding element of the WCF client.  For WCF client configuration, if you are using customBinding, you can directly define the <textMessageEncoding> element, while if you are using some system binding (like basicHttpBinding or wsHttpBinding, you can use the property on <binding> element to configure the textEncoding. e.g.
     <bindings>
       <basicHttpBinding>
        <binding name="utf_8_binding" textEncoding="utf-8" ></binding>
       </basicHttpBinding>
    
       <customBinding>
        <binding name="custombinding1">
         <textMessageEncoding writeEncoding="utf-8" />
         <httpTransport />
        </binding>
       </customBinding>
      </bindings>
    

    so you don't need to manually do the encoding convertion in code. Just setup a proper endpoint with the correctly text encoding (set for the binding) that is corresponding to the service side.

     

    • Marked as answer by Mou_kolkata Sunday, February 9, 2014 8:53 AM
    Friday, February 7, 2014 11:30 AM
  • can u give me any url from where i can know which protocol is used for which binding ? and how to change default binding ? thanks
    Monday, February 10, 2014 6:57 AM