The_Holy_One
The_Holy_One

Reputation: 331

restful service receives "�" instead of umlaut

i call my Rest WebService with the following URL:

... /Service.svc/ChangeMasterData/10?MeasureTypeID=100&LastName=%E4%F6%F6ABC

but instead of getting the correct string "äööABC" in my webservice c# code behind, the string contains only "���ABC".

Any hint where i've forgot something?

--- Additional Information about the C# Code Part ---

IService.cs

[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "ChangeMasterData/{UserID}?MeasureTypeID&{MeasureTypeID}&LastName={LastName});

Service.svc.cs

public string ChangeMasterData(string UserID, string MeasureTypeID, string LastName)
{
    // LastName contains "���ABC" instead of "äööABC"
    ...
}

Fiddler's HexView from the called URL:

enter image description here

Upvotes: 0

Views: 238

Answers (2)

tomsv
tomsv

Reputation: 7277

This part %E4%F6%F6 looks like it is the URL encoding of ISO-8859-1 characters, but your webservice probably expects UTF-8. Either make sure your string is UTF-8 before doing the URL encoding or make sure the URL encoder understands that you want it to encode as UTF-8.

In Javascript that would be encodeURIComponent(str) or encodeURI(str). Javascript escape is deprecated in part because it encodes non-ASCII characters in a non standard way.

Upvotes: 0

Jon Hanna
Jon Hanna

Reputation: 113272

... /Service.svc/ChangeMasterData/10?MeasureTypeID=100&LastName=%E4%F6%F6ABC

Unless you're in the days before RFC 3987 you shouldn't be picking arbitrary encodings to use as the basis for encoding non-ASCII characters in ASCII, so this should be considered either having LastName=���ABC, LastName=��ABC or perhaps LastName=���BC at the end.

instead of getting the correct string "äööABC"

If that's what you wanted, you should have used LastName=%C3%A4%C3%B6%C3%B6ABC

Upvotes: 1

Related Questions