469,609 Members | 1,657 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Change character encoding in the Request

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/U...d-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 <6k*******@sneakemail.com>

Nov 23 '05 #1
6 9011
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

Nov 23 '05 #2
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

Nov 23 '05 #3
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

Nov 23 '05 #4
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

Nov 23 '05 #5
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

Nov 23 '05 #6
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

Nov 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by lkrubner | last post: by
4 posts views Thread by Richard Cornford | last post: by
4 posts views Thread by HeroOfSpielburg | last post: by
6 posts views Thread by Pavils Jurjans | last post: by
18 posts views Thread by james | last post: by
reply views Thread by 6kjfsyg02 | last post: by
44 posts views Thread by Kulgan | last post: by
17 posts views Thread by =?Utf-8?B?R2Vvcmdl?= | last post: by
2 posts views Thread by Vladimir Ghetau | last post: by
reply views Thread by Solution2021 | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.