Solved

How to UTF8 Encode the C# responseModel Object for Web API call

Posted on 2015-01-20
3
228 Views
Last Modified: 2015-02-05
UTF8Encoding utf8 = new UTF8Encoding();
string unicodeString="Quick brown fox";
byte[] encodedBytes = utf8.GetBytes(unicodeString);

This work for a string. How can I do succeed at best doing this for the C# responseModel object before returning from a Web API call?

Thanks!! These odd characters are messing up the presentation layer in an Ipad app.
0
Comment
Question by:gswitz
3 Comments
 
LVL 33

Expert Comment

by:ste5an
ID: 40561479
D'oh? It's hard to guess without any information. Please post a concise and complete example. You're talking about a web api call, but I don't see any in your sample. Also I wouldn't call responseModel a common term - at least I don't know it. So please rephrase your question and give us more information.
0
 

Author Comment

by:gswitz
ID: 40561966
Sorry for not asking a clear enough question.

The object looks like this and actually includes an Objects type...

    public class ResponseModel
    {
        [DataMember]
        [DefaultValue(true)]
        public bool Success { get; set; }
        [DataMember]
        public string ErrorMessage { get; set; }
        [DataMember]
        [DefaultValue(0)]
        public int ErrorCode { get; set; }
        [DataMember]
        public ArrayList DataCollection { get; set; }
        [DataMember]
        public object Data { get; set; }
        [DataMember]
        public int TotalRows { get; set; }

I can go downstream to the objects that inherit from it that looks like this...


    [Serializable]
    [DataContract]
    public class Article : IBaseEntity
    {
        [DataMember]
        public string Type { get; set; }
        [DataMember]
        public List<ArticleInformation> Information { get; set; }

The service model binding includes a specification for UTF8
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
But, would this convert the response to utf-8 or would is depend on the response being utf-8.

Should I create separate questions here? Not sure.

Thanks for responding.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 40562795
"would this convert the response to utf-8 or would is depend on the response being utf-8."
It would send the response as UTF-8.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question