C#/Java Validate Unicode characters in Xamarin Android -


i’m sending xml 3rd party web service. characters in xml causes web service throw exception, example is:

system.servicemodel.faultexception unhandled hresult=-2146233087
message=system.web.services.protocols.soapexception: server unable process request. ---> system.text.encoderfallbackexception: unable translate unicode character \u0193 @ index 281 specified code page.

the exception not thrown in circumstances:

  1. if character within first 0-255 characters of unicode character table, apart in 128-160 range, or
  2. for specific unicode characters above 255 range, such “ƒ” (402). notice of these marked “in wgl4” on page. however, marked “in wgl4” cause exception.

we seeing issue when users type text box, or paste text box word document or email (and text sent web service).

i’d restrict characters can entered text box. start have rudimentary test:

if ((chr > 255) || (!xmlconvert.isxmlchar(chr))) {   // restrict character } 

however, doesn’t permit of valid characters above 255. how can add condition allow these, without resorting hardcoding long list of possible values e.g. there existing method use?

looks server encoding text character set windows-1252, common code page c# code on windows server.

to see if text contains characters can encoded windows-1252, use java code:

string text = ...; charsetencoder encoder = charset.forname("windows-1252").newencoder(); if (! encoder.canencode(text)) {     // text not supported } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -