I have written a client to a web service. I use ASP.NET 1.1 for the
client.
It worked until I tried to send accented characters. Then the service
answered that my signature is not valid. I was told by the people
running the service that their host takes ISO-8859-1 (Latin1) and
nothing else.
I had been sending the default UTF-8. I tried to send Latin1 with this:
RequestEncoding= System.Text.Encoding.GetEncoding( "ISO-8859-1");
in the proxy class.
I tried and it seemed to work, because it had deleted all the accented
characters! Thus the service had no problem to validate the signature.
It had written <?xml version="1.0" encoding="iso-8859-1"?> and the
ContentType was the desired "text/xml; charset=iso-8859-1".
Reading from "GotDotNet User Sample: Encoding SOAP extension" (
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=e5ac0293-
1481-47b0-916d-5186106eb57c
) (including the little comment at the bottom), I added a
SoapExtension that goes before the rest of extensions (those that log a
copy, add a signature,...)
I did things like this:
if( SoapMessageStage.AfterSerialize== message.Stage)
{
if( inwardStream.CanSeek)
{
inwardStream.Position= 0;
}
Regex expReg= new Regex(
System.Text.Encoding.UTF8.HeaderName /* utf-8 */,
RegexOptions.IgnoreCase);
TextReader lector= new StreamReader( inwardStream);
TextWriter escritor;
escritor= new StreamWriter(
// _encoding is "iso-8859-1"
outwardStream, System.Text.Encoding.GetEncoding( _encoding));
SoapMsgTxt= expReg.Replace( SoapMsgTxt, _encoding);
escritor.Flush();
}
It substituted in <?xml ?> but when the next SoapExtension converted
its stream to a string, the accented characters had disappeared.
Then I tried:
escritor= new XmlTextWriter( outwardStream,
System.Text.Encoding.GetEncoding( _encoding));
XmlDocument doc= new XmlDocument();
//SoapMsgTxt is the SOAP XML in a string, read from the stream
doc.LoadXml( SoapMsgTxt);
doc.WriteTo( escritor);
And it appeared mutilated again.
I also tried:
escritor.WriteRaw( SoapMsgTxt);
and even:
if( SoapMessageStage.BeforeSerialize== message.Stage)
{
message.ContentType= "text/xml; charset=iso-8859-1";
// I can call the base. I am inheriting from a subclass
// of SoapExtension
base.ProcessMessage( message);
}
It kept mutilating characters.
Any suggestion on how I can convert my Request to ISO-8859-1?
Thanks in advance.
--
David Mediavilla <6kjfsyg02@sneakemail.com>
6kjfsyg02@sneakemail.com - 29 Jun 2005 13:07 GMT
I forgot that I also tried changing <globalization /> in the web.config
just in case. But it doesn't work on the service, only on the ASP.NET
forms.
--
David Mediavilla
6kjfsyg02@sneakemail.com - 01 Jul 2005 13:01 GMT
I removed the special SoapExtension and changed in the base class of my
SoapExtensions:
case SoapMessageStage.BeforeDeserialize:
readStr = new StreamReader(outwardStream,
System.Text.Encoding.GetEncoding( "ISO-8859-1"));
SoapMsgTxt = readStr.ReadToEnd();
writeStr = new StreamWriter(
inwardStream, readStr.CurrentEncoding);
//[...]
case SoapMessageStage.AfterSerialize:
inwardStream.Position = 0;
readStr = new StreamReader(inwardStream,
System.Text.Encoding.GetEncoding( "ISO-8859-1"));
SoapMsgTxt = readStr.ReadToEnd();
writeStr = new StreamWriter(
outwardStream, readStr.CurrentEncoding);
while setting RequestEncoding to ISO-8859-1.
It still removes accented characters.
ISO-8859-15 behaves as -1.
Setting RequestEncoding to AsciiEncoding, however, substitutes accented
characters by question marks.
--
David Mediavilla
6kjfsyg02@sneakemail.com - 05 Jul 2005 15:25 GMT
I removed all the SoapExtensions from web.config, set RequestEncoding
to ISO-8859-1, and looked at the HTTP traffic with ProxyTrace. This
time the accented characters were conserved in the transmision. So
something in the SoapExtensions damages them.
I also tried the application in Visual Studio 2005 Beta 2.
Setting RequestEncoding to ISO-8859-1, instead of removing the accented
characters converts them to question marks.
--
David Mediavilla