* Changed XmlRpc to specify utf-8

afrisby
lbsa71 2007-07-05 18:31:59 +00:00
parent f7a938a21d
commit 8df2119bc7
4 changed files with 26 additions and 13 deletions

View File

@ -31,6 +31,7 @@ namespace Nwc.XmlRpc
using System.IO; using System.IO;
using System.Net.Sockets; using System.Net.Sockets;
using System.Collections; using System.Collections;
using System.Text;
///<summary>Very basic HTTP request handler.</summary> ///<summary>Very basic HTTP request handler.</summary>
///<remarks>This class is designed to accept a TcpClient and treat it as an HTTP request. ///<remarks>This class is designed to accept a TcpClient and treat it as an HTTP request.
@ -55,8 +56,10 @@ namespace Nwc.XmlRpc
public SimpleHttpRequest(TcpClient client) public SimpleHttpRequest(TcpClient client)
{ {
_client = client; _client = client;
_output = new StreamWriter(client.GetStream());
_input = new StreamReader(client.GetStream()); _output = new StreamWriter(client.GetStream(), Encoding.UTF8 );
_input = new StreamReader(client.GetStream(), Encoding.UTF8 );
GetRequestMethod(); GetRequestMethod();
GetRequestHeaders(); GetRequestHeaders();
} }

View File

@ -56,7 +56,7 @@ namespace Nwc.XmlRpc
public class XmlRpcRequest public class XmlRpcRequest
{ {
private String _methodName = null; private String _methodName = null;
private Encoding _encoding = new ASCIIEncoding(); private Encoding _encoding = new UTF8Encoding();
private XmlRpcRequestSerializer _serializer = new XmlRpcRequestSerializer(); private XmlRpcRequestSerializer _serializer = new XmlRpcRequestSerializer();
private XmlRpcResponseDeserializer _deserializer = new XmlRpcResponseDeserializer(); private XmlRpcResponseDeserializer _deserializer = new XmlRpcResponseDeserializer();

View File

@ -30,6 +30,7 @@ namespace Nwc.XmlRpc
using System; using System;
using System.Xml; using System.Xml;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text;
/// <summary>The class is a container of the context of an XML-RPC dialog on the server side.</summary> /// <summary>The class is a container of the context of an XML-RPC dialog on the server side.</summary>
/// <remarks>Instances of this class maintain the context for an individual XML-RPC server /// <remarks>Instances of this class maintain the context for an individual XML-RPC server
@ -98,8 +99,9 @@ namespace Nwc.XmlRpc
if (Logger.Delegate != null) if (Logger.Delegate != null)
Logger.WriteEntry(xmlRpcResp.ToString(), LogLevel.Information); Logger.WriteEntry(xmlRpcResp.ToString(), LogLevel.Information);
XmlRpcServer.HttpHeader(httpReq.Protocol, "text/xml", 0, " 200 OK", httpReq.Output); XmlRpcServer.HttpHeader(httpReq.Protocol, "text/xml", 0, " 200 OK", httpReq.Output);
httpReq.Output.Flush(); httpReq.Output.Flush();
XmlTextWriter xml = new XmlTextWriter(httpReq.Output); XmlTextWriter xml = new XmlTextWriter(httpReq.Output);
_serializer.Serialize(xml, xmlRpcResp); _serializer.Serialize(xml, xmlRpcResp);
xml.Flush(); xml.Flush();

View File

@ -31,6 +31,7 @@ namespace Nwc.XmlRpc
using System.Collections; using System.Collections;
using System.IO; using System.IO;
using System.Xml; using System.Xml;
using System.Text;
/// <summary>Base class of classes serializing data to XML-RPC's XML format.</summary> /// <summary>Base class of classes serializing data to XML-RPC's XML format.</summary>
/// <remarks>This class handles the basic type conversions like Integer to &lt;i4&gt;. </remarks> /// <remarks>This class handles the basic type conversions like Integer to &lt;i4&gt;. </remarks>
@ -53,15 +54,22 @@ namespace Nwc.XmlRpc
/// <seealso cref="XmlRpcRequest"/> /// <seealso cref="XmlRpcRequest"/>
public String Serialize(Object obj) public String Serialize(Object obj)
{ {
StringWriter strBuf = new StringWriter(); using (MemoryStream memStream = new MemoryStream(4096))
XmlTextWriter xml = new XmlTextWriter(strBuf); {
xml.Formatting = Formatting.Indented; XmlTextWriter xml = new XmlTextWriter(memStream, Encoding.UTF8);
xml.Indentation = 4; xml.Formatting = Formatting.Indented;
Serialize(xml, obj); xml.Indentation = 4;
xml.Flush(); Serialize(xml, obj);
String returns = strBuf.ToString(); xml.Flush();
xml.Close();
return returns; byte[] resultBytes = memStream.ToArray();
UTF8Encoding encoder = new UTF8Encoding();
String returns = encoder.GetString( resultBytes, 0, resultBytes.Length );
xml.Close();
return returns;
}
} }
/// <remarks>Serialize the object to the output stream.</remarks> /// <remarks>Serialize the object to the output stream.</remarks>