locked
How to generate UTF-16 based requests via the Data Services client RRS feed

  • Question

  • I am working on some internationalization support and am relatively new to the WCF Data Services framework. Using Fiddler I have sniffed the request being generated by the WCF Data Services client to be generating request payloads which encoded using UTF-8 based as shown below:

    POST /service.svc/Customers HTTP/1.1

    Host: host

    Content-Type: application/atom+xml

    Accept: application/atom+xml

     

    <?xml version="1.0" encoding="utf-8"?>

    <entry xml:base="http://host/service.svc/"

         xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"

         xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"

         xmlns="http://www.w3.org/2005/Atom">

      <id>http://host/service.svc/Customers('ASDFG')</id>

      <title type="text" />

      <updated>2008-12-07T8:00:00Z</updated>

      <author>

        <name />

      </author>

      <link rel="http://schemas.microsoft.com/ado/2007/08

      /dataservices/related/Orders"

            href="Orders(1)" />

      <link rel="http://schemas.microsoft.com/ado/2007/08

      /dataservices/related/Orders"

            href="Orders(2)" />

      <content type="application/xml">

       <m:properties>

        <d:CustomerID>ASDFG</d:CustomerID>

        <d:CompanyName>Contoso Widgets</d:CompanyName>

        <d:Address>

          <d:Street>58 Contoso St</d:Street>

          <d:City>Seattle</d:City>

        </d:Address>

       </m:properties>

      </content>

    </entry>



    Is there a way to generate some other encoding such as UTF-16, UTF-32, etc using the WCF Data Services client? Also if there is a way to specify the encoding of the response payload on the request being sent (ie the Accept-charset value)?

    Thanks in anticipation,
    Piyush.
    Monday, January 25, 2010 4:30 PM

Answers

All replies

  • Hi,

    As far as I know we currently don't support any other encoding than UTF-8. On the other hand, the question is why do you need UTF-16?
    UTF-8, UTF-16 and UTF-32 are just different ways to encoding the same character space (the Unicode), so there's no difference in the number of supported characters between the encodings. The only difference is how exactly are they written into bytes. The UTF-8 is usually the most space sacing encoding (uses least bytes), that's why it's used here to decrease the amount of data necessary to transfer over the network.

    Thanks,
    Vitek Karas [MSFT]
    Monday, January 25, 2010 5:33 PM
    Moderator
  • Hi Vitek,

    Thanks for replying.

    1. It is not UTF-16, per se, that is required. The reason for asking is that many a times, the client can be running on a platform that has a native encoding in use (such as Traditional Chinese, etc) which are not UTF-8 compatible. It would save an encoding/decoding step on the client from the native encoding to UTF-8 if we can directly send requests encoded in the native encoding.
    2. Playing with Fiddler, I was able to specify an Accept-charset header like UTF-16 on the request, the WCF Data Service responds with a payload encoded in UTF-16. However I was not able to figure out how to set this Accept-charset header via the WCF data services client. Is there a way to do so?
    3. Also is there a list of supported charsets that the WCF Data Service supports, or will it support any charset that is installed on the OS it is running on?
    Monday, January 25, 2010 10:29 PM
  • Hi,

    1) I see, thanks for the explanation.
    2) Nice, didn't know we supported this. You can modify the headers of a request sent from the client by hooking the DataServiceContext.SendingRequest event. (http://msdn.microsoft.com/en-us/library/system.data.services.client.dataservicecontext.sendingrequest.aspx).
    3) I don't know for sure, but a safe guess would be whatever encodings are supported by the .NET Framework running on the server (service) assuming this is using the WCF Data Services library to implement the server-side. Remember that not all services exposing data through the OData protocol are implemented using the WCF Data Services library and thus their particular behavior might be a bit different.

    Thanks,
    Vitek Karas [MSFT]
    Tuesday, January 26, 2010 2:32 AM
    Moderator
  • Hello,


    How is the problem?  I think Vitek's posts are really helpful!   If you need any further assistance, please feel free to let me know.
     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, February 1, 2010 1:05 AM
    Moderator