473,473 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Changing XML encoding using SoapExtension

Hi,

I have double byte characters in the content that I am returning using Web
Services. However, the encoding in the xml file returned by Web Services is
utf-8 and I am unable to read the content, not even by changing browser
encoding setting to the appropriate one.

I implemented SoapExtension (called EncodingExtension) to rewrite the xml to
change the encoding="utf-8" to encoding="windows-1252" in BeforeDeserialize
SoapMessage stage on the server side. I am able to see the modified xml when
viewing it with WebServiceStudio 2.0 (a WinForm app). but I am unable to get
the same change when using a web application, where I view it using simply
invoking the same webmehod from the browser (calling asmx page directly in
the browser).

Invoking it in WebServiceStudio, I am able to debug and step though the
SoapExtension class. But invoking webmethod directly in the browser, I am
unable to step through, as if the SoapExtension class isn't being called at
all, which explains why the changes to xml stream aren't applied. Though I
did get as far as to the EncodingExtensionAttribute class, ExtensionType
function. But it won't run the EncodingExtension class.

My SoapExntension class obvious works. So my questions is, what do I have
to do to get the SoapExtension to run when invoking Web Services from a web
application?

I am using .NET Framework 2.0, Visual Studio 2005 RTM. I want the XML file
to have windows-1252 encoding. This xml is sending it to my aspx page that
uses Atlas to call Web Services. Now I am wondering if this is even the
correct approach?

Please help! Below are some of my code setup and the result.

Thanks.

JaN
----------- SETUP -----------------:
WebService.asmx:
[EncodingExtension]
[WebMethod]
public Weblog GetWeblogDebug(int weblogid, int userId) { //some code }

XWebServices.EncodingExtension (inherit from SoapExtension):

private void AlterEncoding(SoapMessage message)
{
if (message.Stage == SoapMessageStage.AfterSerialize)
{
newStream.Position = 0;
TextReader reader3 = new StreamReader(newStream);
string str = reader3.ReadToEnd();
int pos = str.IndexOf("<GetWeblogDebugResponse");
int pos2 = str.IndexOf("</GetWeblogDebugResponse>");
string soapBodyString = str.Substring(pos, pos2 - pos + 25);
soapBodyString = soapBodyString.Replace("<Title>null</Title>",
"<Title>Hello</Title>");
soapBodyString = soapBodyString.Replace("<Title />", "<Title>Hello</Title>");

String xmlVersionString = "<?xml version=\"1.0\" encoding=\"big5\"?>";
String soapEnvelopeBeginString = "<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\">";
String soapBodyBeginString = "<soap:Body>";
String soapBodyEndString = "</soap:Body>";
String soapEnvelopeEndString = "</soap:Envelope>";

Stream appOutputStream = new MemoryStream();
StreamWriter soapMessageWriter = new StreamWriter(appOutputStream);
soapMessageWriter.Write(xmlVersionString);
soapMessageWriter.Write(soapEnvelopeBeginString);
soapMessageWriter.Write(soapBodyBeginString);
soapMessageWriter.Write(soapBodyString);
soapMessageWriter.Write(soapBodyEndString);
soapMessageWriter.Write(soapEnvelopeEndString);
soapMessageWriter.Flush();

appOutputStream.Flush();
appOutputStream.Position = 0;
StreamReader reader = new StreamReader(appOutputStream,
System.Text.Encoding.GetEncoding(1252));
StreamWriter writer = new StreamWriter(oldStream,
System.Text.Encoding.GetEncoding(1252));
writer.Write(reader.ReadToEnd());
writer.Flush();
appOutputStream.Close();
}}
------------- RESULT -------------------:

The <Title> is what I manually changed (in additition to encoding), to see
if it actually works. Because for some reason WebServiceStudio always use
utf-16, but I am always seeing Title being changed to "Hello" as intended in
the code. In the browser generated xml, the title is not changed, and xml
encoding is always utf-8.

/WeblogEditorService.asmx/GetWeblogDebug Result:
<?xml version="1.0" encoding="utf-8" ?>
- <Weblog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<weblogChangeOnly>true</weblogChangeOnly>
<epropStatusChange>0</epropStatusChange>
<UserId>41</UserId>
<UniqueId>992</UniqueId>
<Title />

<Body>¤é¸g«ü¼Æ¬Q¦¬¦Ü15551.31¡A¦]§ë¸ê¤H¶R¶i¿ûÅKªÑ¡A³Ð³æ¤é¦¨¥ ¬ö¿ý·s°ª¡Cserverinsert</Body>
</Weblog>

WebServiceStudio 2.0 Result:
ResponseCode: 200 (OK)
Connection:Close
Content-Length:944
Cache-Control:private, max-age=0
Content-Type:text/xml; charset=utf-8
Date:Sat, 10 Dec 2005 23:59:55 GMT
Server:ASP.NET Development Server/8.0.0.0
X-AspNet-Version:2.0.50727

<?xml version="1.0" encoding="utf-16"?>
<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>
<GetWeblogDebugResponse xmlns="http://tempuri.org/">
<GetWeblogDebugResult>
<weblogChangeOnly>true</weblogChangeOnly>
<epropStatusChange>0</epropStatusChange>
<UserId>41</UserId>
<UniqueId>992</UniqueId>
<Privacy>2</Privacy>
<Title>Hello</Title>

<Body>¤é¸g«ü¼Æ¬Q¦¬¦Ü15551.31¡A¦]§ë¸ê¤H¶R¶i¿ûÅKªÑ¡A³Ð³æ¤é¦¨¥ ¬ö¿ý·s°ª¡Cserverinsert</Body>
</GetWeblogDebugResult>
</GetWeblogDebugResponse>
</soap:Body>
</soap:Envelope>

----------------------------------
WebServiceStudio 2.0:

http://www.gotdotnet.com/Community/U...4-e916ebc4159c
Dec 11 '05 #1
2 5565
I just saw this:

http://www.dotnet247.com/247referenc...45/228371.aspx

"If you're testing this by hitting the "Invoke" button on the .asmx page, it
will never work. That execution path does not send any SOAP message to the
ASP.NET runtime, and no SOAP Extension will ever get executed. You need to
generate a client and use it to send some traffic at the service if you want
to test your extension."
That answered my question, but it didn't solve my problem. I did what he
said, create a client page to call Web Service, but only that I am using
Atlas. It still doesn't work. Is it because of how Atlas works that it
doesn't go through SoapExention? Is what I wanted to do simply NOT possible?
Can someone please point me to the right direction on this? If I can't use
SoapExtension, what can I use? Modify the XML in HttpHandler?

Thanks,

JaN
Dec 11 '05 #2
I just saw this:

http://www.dotnet247.com/247referenc...45/228371.aspx

"If you're testing this by hitting the "Invoke" button on the .asmx page, it
will never work. That execution path does not send any SOAP message to the
ASP.NET runtime, and no SOAP Extension will ever get executed. You need to
generate a client and use it to send some traffic at the service if you want
to test your extension."
That answered my question, but it didn't solve my problem. I did what he
said, create a client page to call Web Service, but only that I am using
Atlas. It still doesn't work. Is it because of how Atlas works that it
doesn't go through SoapExention? Is what I wanted to do simply NOT possible?
Can someone please point me to the right direction on this? If I can't use
SoapExtension, what can I use? Modify the XML in HttpHandle?

Thanks,

JaN
Dec 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: fred carter | last post by:
I would like to be able to set an arbitrary http header from a SoapExtension when said extension is acting on behalf of a client. I have not seen a means for doing so. For incoming messages or...
4
by: Matthew Roche | last post by:
Greetings: I am developing an application that uses an ASP.NET Web Forms application for its UI and ASP.NET web services for its business tier, and I am looking for assistance in improving my...
3
by: Trevor Pinkney | last post by:
Hi, Is it possible to reference a custom SoapExtension instance from within a WebMethod? I have a SoapExtension used by several web-services for generic logging. The SoapExtension logs the...
0
by: 6kjfsyg02 | last post by:
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...
0
by: Symon | last post by:
I've got a web service project that was built under VS 2003 which has a SoapExtension in the project. The SoapExtension is registered in the <soapExtensionTypes> element of the web.config and has...
7
by: Jeffrey Spoon | last post by:
Hello, I'm a bit stuck trying to convert a text file which contains extended ASCII text and changing the ASCII values so they become readable. I do this by subtracting 127 from the ASCII value....
10
by: Andy Kendall | last post by:
I have a problem accessing my custom SoapHeader from a SoapExtension. My extension has no compile time reference to the class derived from SoapHeader, so how can cast it into a SoapHeader of the...
3
by: =?Utf-8?B?Q0V2YW5z?= | last post by:
My Environment * Windows XP * .NET 2.0 * Visual Studio 2005 I have written a SoapExtension in c# on a windows XP machine. The purpose of this extension is to monitor progress for data...
1
by: =?Utf-8?B?RWRkaWUgSg==?= | last post by:
I'm trying to define a SoapExtensionAttribute to tag web service method calls that should run through a SoapExtension. However, I can only get it to work when the SoapExtension is defined in the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.