Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

German umlauts in EndpointAddress with net.tcp

Tags:

c#

wcf

I'm trying to make instance of class EndpointAddress where parameter contains German umlaut.

For example:

EndpointAddress endpointAddress = new EndpointAddress("net.tcp://süd:8001/EmployeeService");

It always throws exception that given uri cannot be parsed. I have tried to replace the umlaut with an encoded value, but I get same exception:

Invalid URI: The hostname could not be parsed.

Did anyone had same problem before? Thank you in advance.

like image 387
Nenad Avatar asked Feb 20 '13 14:02

Nenad


3 Answers

The parser probably doesn't know how to work with internationalized domain names (IDN). If you want to have such hostnames, you're going to have to do the Punycode encoding yourself. I haven't used it, but there's a core function IdnMapping.GetAscii that looks suitable — something like

EndpointAddress endpointAddress = new EndpointAddress(
    "net.tcp://" + IdnMapping.GetAscii("süd") + ":8001/EmployeeService"
);

will perhaps work (forgive me if it doesn't, C# isn't my language).

like image 118
hobbs Avatar answered Nov 15 '22 11:11

hobbs


Just as an extra note. WCF added support for IDN (both for hosting service + WCF client talking to a service with IDN name) in .Net 4.5. This documentation has some information about this.

So this exception will disappear as soon as you compile your app against .net 4.5

like image 2
Praburaj Avatar answered Nov 15 '22 10:11

Praburaj


As suggested you have to enable IRI and IDN parsing before using this kind of URI.

Add this to your app.config:

 <configuration>
     <uri>
         <idn enabled="All" />
         <iriParsing enabled="true" />
     </uri>
 </configuration>
like image 1
deramko Avatar answered Nov 15 '22 12:11

deramko