Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hey Audio! 3 29
Sent email using Shared Mailbox from outlook in C# 5 24
Printing 1 51
VS2013 publish C# application Created folder -- where is it??? 10 15
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

772 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