How can UTF-16 data be supported in Web Service?

J

joep

We have a Web Service that appears to handle some Unicode data properly. We
have our web.config file set for Unicode encoding of socket messages to our
backend server application (i.e., Encoding.Unicode) and we have the
globalization settings for requestEncoding and responseEncoding set to utf-8.
I have successfully sent and received utf-8 data via a C++ client using gSoap
thru the Web Service and backend server. I have done the same via ASP.NET C#
web samples as well.

However, I tried changing the requestEncoding and responseEncoding of the
web.config file for the Web Service to utf-16 and started running into
issues. One thing I noticed is that with this setting, I can display the Web
Service in IE (navigating to http://localhost/MyService/MyService.asmx), but
when I try to view the WSDL (via the Service Desription link,
http://localhost/MyService/MyService.asmx?WSDL) it doesn't load it. I'm not
able to get the clients to work with these utf-16 settings either. What all
needs to be changed to handle utf-16 (all file encodings are utf-8 but I
don't know if that matters...)?

Thanks.
 
D

Dan Rogers

Hi,

In general, the clients will need to be set up with the same web.config
(but in app.config) that you made on the server. The IE issues are going
to be different, since the WSDL is now (hopefully) being generated in
UTF-16, and the automatic XSLT may not be able to deal with a UTF-16
encoded XML document. Since UTF-8 can handle most double byte characters,
what is the business need driving your decision to switch things over?

As far as writing out files, you'll have to make sure you write out using
an encoding sensitive writer - and presuming that any string data is
properly decoded to Unicode and then written out as UTF-16 (the
XmlTextWriter can do this if you use the proper over-ride), the actual data
should be fine.

I hope this helps,

Dan Rogers
Microsoft Corporation
--------------------
 
J

joep

I did modify the ASP.NET web samples web.config files to match the web
service settings of utf-16 for requestEncoding and responseEncoding and I
could not get it to work. Have you tried this? I must be missing some piece.

As far as the business need for utf-16 - there is no real requirement for it
except that our customers may choose to modify the web service web.config
file and set it to utf-16 for their needs (i.e., reading in data from a file
saved in utf-16 format). I just wanted to make sure our sample clients would
work if they chose to do that. We will default our web service and sample
clients to utf-8 as I know that works fine. Thanks.
 
D

Dan Rogers

Hi Joe,

If it works in UTF-8 but not in UTF-16, then I suspect there is some issue
with the actual data you are dealing with. The serializer is perfectly
capable of processing incoming data in UTF-16 (yes, I've tried this).
Getting data written out that you can read and test with in UTF-16 is an
option on the serializer.

As for "what if the clients choose" - my advice is to make the encoding of
responses a part of the service contract that you make when you acquire a
client that you wish to support. Making an incoming UTF-16 request turn
into a UTF-16 response, when the server normally sends responses in UTF-8
is nigh difficult. My advice is to be able to accept requests encoded in
UTF-8, but set expectations that all responses will be in the default XML
encoding (UTF-8). This is what we decided was reasonable when we wrote the
UDDI specifications.

I hope this helps

Dan Rogers
Microsoft Corporation
--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top