Solved

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

Posted on 2015-01-20
3
236 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

696 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