Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8421719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:13:28+00:00 2026-06-10T03:13:28+00:00

I have a small web service in C# 4.0 which returns data via JSONP.

  • 0

I have a small web service in C# 4.0 which returns data via JSONP. The problem I have is that non-ASCII characters – like the German umlauts (ä, ö, ü) – are scrambled when they arrive in the client. To following simplified code illustrates this:

// The interface
[OperationContract]
[WebGet( ResponseFormat = WebMessageFormat.Json )]
string GetTestString();

//...

// The implementation
public string GetTestString()
{
    return "String with some German characters: äöüß";
}

Now if I access the web method through Firefox by entering the URL http://localhost:31843/TestWebService/GetTestString I get the correct result:

"String with some German characters: äöüß"

However if I specify the callback parameter in the URL (http://localhost:31843/TestWebService/GetTestString?callback=Test), which is what JSONP does, I get a scrambled result:

Test("String with some German characters: äöüß");

The JSONP serializer is that of the Microsoft .NET 4.0 framework which I activated by setting webHttpBinding.CrossDomainScriptAccessEnabled = true; in my code.
I didn’t find any way to influence the character encoding of that serializer. Do you have any ideas?

Another hint: After the web request for the JSONP string with the scrambled characters, Firebug shows the following error on the console:

“The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.”

Obviously this seems to be the problem. But the question is, how to configure the correct encoding (and why isn’t it UTF8 by default)?

Update:

I think the Microsoft .NET DataContractJsonSerializer has a bug. In the first case with JSON, it sends the following HTTP header:

Content-Type: application/json; charset=utf-8

When using JSONP by specifiying the callback URL parameter, it sends:

Content-Type: application/x-javascript

So no character encoding is specified, leaving the decision of the character set up to the browser. After some research in the Internet I’m convinced that there is no (easy) way to force the DataContractJsonSerializer to send out a Content-Type HTTP header with a proper charset.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:13:30+00:00Added an answer on June 10, 2026 at 3:13 am

    I have now found a pretty simple solution to this – maybe a bit artificial – problem.

    Explanation: I’m developing an app for smartphones with a JavaScript framework, so it’s no native app but runs in the smartphone’s browser engine. For this reason, all web content (HTML, JavaScript, CSS files, etc.) is loaded locally, not remote from a web server. That’s why there’s no appropriate Content-Type HTTP header with a charset, because there is no HTTP at all. In the index.html file, which is the main page (the one and only) for the app, there was also no charset specified. So the browser assumed some default charset, unfortunately not UTF-8.

    So the simple solution for me was to specify the character set in the index.html by adding the following line:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    

    That way, also the embedded JSONP data now gets displayed correctly, without requiring the JSONP HTTP response to have its character set specified explicitly.

    Of course, this doesn’t resolve the incorrect display in Firefox, as stated in my question above. But this doesn’t matter, as it only has to be displayed correctly on the smartphone’s browser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined small MXML component which calls web service which returns random number
We have a web service which serves small, arbitrary segments of a fixed inventory
I have developed a small C# form application which calls a web service. Everything
I have a small app which query our SharePoint server' Web Service interface for
I have small web app that generate PDF files as a report. I'm trying
I am thinking of making an (initially) small Web Application, which would eventually have
I have a Hello World c# ASP .NET web service which is automatically generated
I have a SOAP web service that is defined contract-first--the request and response xml
So i have an array that i retrieve from a web service in no
I have a small web application that I am building. Primarily to improve my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.