I am using VS.NET to create a web service in C#. I have set the
globalization parameters in the Web.config file to use ISO-8859-1 as both
the requestEncoding and the responseEncoding. (Note that regardless of these
settings, the XML returned by the web service uses UTF-8... that seems to be
a bad sign, although I'm not as worried about the response as I am parsing
the request.)
I am using VB 6 to generate SOAP calls to the web service. I generate my
own proxy classes in VB and use my own SoapClient and SoapReader classes
that I wrote (these provide the same functionality of the SOAP Toolkit, with
the addition of an asynchronous SOAP call model to make up for the SOAP
toolkit deficiency of only providing synchronous calls to the SOAP methods,
as well as providing the ability to specifiy the desired encoding). I use
the XMLHTTP30 class to make the SOAP calls. I specify the content-type of
text/xml as well as charset=ISO-8859-1. I make sure to include the XML
declaration at the start of the XML content that specifies the encoding,
<?xml version=1.0" encoding="iso-8859-1" ?>
All of this works great and I have web services in production using all this
code. The only problem is that the XML encoding is not respected at some
point: the parameter to my web service method is a .NET XmlNode, but when I
look at the contents of the XmlNode any ISO-8859-1 but non-ASCII characters
have been turned into question marks, "?".
Does anyone have any suggestions on what I may be doing wrong? Are the
globalization elements of Web.config known to be functional?
Thanks in advance,
Eric Nichols
Software Engineer
Have you found any solution for this problem? I'm having the exact
same problem and I cannot figure out how to change the encoding of my
web service from utf-8 to iso-8859-1. when I send a soap message to my
web service with latin characters, they are removed from my message,
and that is causing allot of problems.
If you have found a way to change this, let me know.
Thanks allot,
Eurico
"Eric Nichols" <eric.n...@intellichem.com> wrote in message news:<#wU7AdgdCHA.3556@tkmsftngp08>...
If this is a .NET problem as opposed to user error, I would like to know
so that I could plan accordingly. Currently I only have a short list of
non-ASCII characters that I need to support, so I do a clunky
search-and-replace on known strings that will contain question marks "?"
when the encoding isn't working, but this is a bad solution and won't work
in the long term. Also, I'm stuck with ISO-8859-1 as it is used throughout
our architecture; switching to UTF-8 is not an option.
Hoping for some advice,
Eric Nichols
"eurico" <ejc...@oninet.pt> wrote in message
news:67235c8e.02101...@posting.google.com...
I'm trying to get a clear answer on this. Hopefully I will have something
today.
thanks,
Yann
"Eric Nichols" <eric.n...@intellichem.com> wrote in message
news:OnFI8njdCHA.2392@tkmsftngp08...
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.IO;
using System.Diagnostics;
using System.Xml;
using System.Text;
namespace WSStudy
{
public class EncodingExtension : SoapExtension
{
Stream newStream;
Stream oldStream;
Encoding encoding;
public override object GetInitializer(LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute)
{
return ((EncodingExtensionAttribute) attribute).Encoding;
}
public override object GetInitializer(Type WebServiceType)
{
return WebServiceType.GetType();
}
public override void Initialize(object initializer)
{
encoding = (Encoding)initializer;
}
public override void ProcessMessage(SoapMessage message)
{
switch (message.Stage)
{
case SoapMessageStage.BeforeDeserialize:
WriteInput( message );
break;
case SoapMessageStage.AfterDeserialize:
break;
case SoapMessageStage.BeforeSerialize:
break;
case SoapMessageStage.AfterSerialize:
WriteOutput( message );
break;
default:
throw new Exception("invalid stage");
}
}
public override Stream ChainStream( Stream stream )
{
oldStream = stream;
newStream = new MemoryStream();
return newStream;
}
public void WriteOutput( SoapMessage message )
{
newStream.Position = 0;
TextReader reader = new StreamReader(newStream);
TextWriter writer = new StreamWriter(oldStream);
StringBuilder sb = new StringBuilder(reader.ReadToEnd());
sb.Replace("utf-8", encoding.WebName);
writer.WriteLine(sb);
writer.Flush();
}
private void WriteInput(SoapMessage message)
{
Copy(oldStream, newStream);
newStream.Position = 0;
}
private void Copy(Stream sourceStream, Stream destinationStream)
{
TextReader reader = new StreamReader(sourceStream);
TextWriter writer = new StreamWriter(destinationStream);
writer.WriteLine(reader.ReadToEnd());
writer.Flush();
}
}
[AttributeUsage(AttributeTargets.Method)]
public class EncodingExtensionAttribute : SoapExtensionAttribute
{
private Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
private int priority;
public override Type ExtensionType
{
get { return typeof(EncodingExtension); }
}
public override int Priority
{
get { return priority; }
set { priority = value; }
}
public Encoding Encoding
{
get { return encoding; }
set { encoding = value; }
}
}
}
Pierre
--
---------------------------------------------------------------
Pierre Greborio
pie...@pierregreborio.it
http://www.pierregreborio.it
UGIDOTNET http://www.ugidotnet.org
---------------------------------------------------------------
So your Content-type header should look something like this:
Content-type: "text/xml; charset='iso-8859-1'"
Also, have you done a netmon sniff to verify that the data on the wire is
properly encoded?
thanks,
Yann
"Yann Christensen" <xws...@online.microsoft.com> wrote in message
news:Od8ddcudCHA.1476@tkmsftngp10...
<?xml version="1.0" encoding="iso-8859-1" ?>
- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Body>
<GetPerson xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
The problem is that the response stream contains always the same encoding:
<?xml version="1.0" encoding="utf-8" ?>
- <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <soap:Body>
- <GetPersonResponse xmlns="http://tempuri.org/">
- <Persona>
<FirstName>Pierre</FirstName>
<LastName>Greborio</LastName>
- <Fc>
<FC>FFGFDRE54654DFD</FC>
</Fc>
</Persona>
</GetPersonResponse>
</soap:Body>
</soap:Envelope>
The only solution I found was to implement a SoapExtension as you can see on
this thread.
Thanks
Pierre
--
---------------------------------------------------------------
Pierre Greborio
pie...@pierregreborio.it
http://www.pierregreborio.it
UGIDOTNET http://www.ugidotnet.org
---------------------------------------------------------------
"Yann Christensen" <xws...@online.microsoft.com> wrote in message
news:evewuxudCHA.1544@tkmsftngp09...
1. I am using the SOAP toolkit's (v3) Trace Utility to see the SOAP
request, as opposed to using netmon; on my development workstation I don't
believe I have netmon installed and I've never used it. Should I do so?
2. When I look at the message in the Trace Utility it starts out like this:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
- <SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
- <SOAP-ENV:Body>
but when I look at the HTTPHeaders in the Trace Utility, I see:
...
<content-type>text/xml</content-type>
...
Perhaps this is the problem, because the charset part of the content-type
isn't displayed here. But I do set it when I create the HTTP request.
Here's the VB client code I'm using. g_xhr is an instance of XMLHTTP30.
' Connect to the web service
g_xhr.open "POST", g_strEndPointURL, bolAsync
g_xhr.setRequestHeader "Content-Type", "text/xml; charset='ISO-8859-1'"
Do you see anything wrong with this? I don't know if this is really setting
the charset properly or not. However, when I view the content in the SOAP
message with the Trace Utility, my Latin characters do show up fine. Of
course, I still have the problem where in the Web Service code the latin
characters have become ? marks.
Please let me know if you think I'm doing something wrong here... and
thanks again for the reply.
Best Regards,
Eric Nichols
Software Engineer
"Yann Christensen" <xws...@online.microsoft.com> wrote in message
news:evewuxudCHA.1544@tkmsftngp09...
Cheers,
Eric
"Pierre Greborio" <pie...@pierregreborio.it> wrote in message
news:uJiTsiudCHA.1300@tkmsftngp08...
Thanks again,
Eric
"Yann Christensen" <xws...@online.microsoft.com> wrote in message
news:evewuxudCHA.1544@tkmsftngp09...