Hi, Keenan. Thanks for the response.
The problem is on the consumer of the web service. They want the XML
document.
I don't want to write another WebMethod just for this. I'd like to know how
to serialize the returned data to an XML doc. The following code will do it
and save it to disk, but ultimately I want not to write it to disk, but
rather store it in a "string" variable:
System.Xml.Serialization.XmlSerializer s = new
System.Xml.Serialization.XmlSerializer(typeof(seResults),https://www.somedomain.com/RatingHub);
Stream fs = new FileStream("D:\\stream.txt",
FileMode.Truncate );
XmlWriter writer = new XmlTextWriter(fs, new
UTF8Encoding());
s.Serialize(writer, results);
Any thoughts?
Thanks again,
Mike
> Mike you should be able to pass the XmlElement object without a
> problem.
[quoted text clipped - 5 lines]
> return myXmlElement; //System.Xml.XmlElement
> }
Keenan Newton - 18 Feb 2005 03:18 GMT
OK you need to find out what object type they are expecting on their
end if it a string or XMlNode, or XmlElement, typically a XmlNode will
accept a XmlDocument or XmlElement. An XmlElement is essentially or it
can be the Xml within an Xmldocument. the XmlDocument class has a
property called DocumentElement. This is essentially all the XML in a
"XmlDocument" The DocumentElement if you look at it really is of type
XmlElement. So if they want it as a string of Xml you again can use
the XmlElement, and return the OuterXml element. So First things first
find out the exact data type they want XmlDocument, XmlNode, XmlElement
or string. Oh yes don't use the filestream use a MemoryStream if
possible
Trevor Pinkney - 21 Feb 2005 19:20 GMT
This should do what you want.
/// <summary>
/// Converts an object to its xml representation
/// </summary>
public static string ObjectToXml(object objectToConvert)
{
MemoryStream memStream = new MemoryStream();
XmlSerializer serializer = new XmlSerializer(objectToConvert.GetType());
serializer.Serialize(memStream, objectToConvert);
StreamReader reader = new StreamReader(memStream);
memStream.Position = 0;
return reader.ReadToEnd();
}
-Trevor
Hello MikeL,
> Hi, Keenan. Thanks for the response.
>
[quoted text clipped - 34 lines]
>> return myXmlElement; //System.Xml.XmlElement
>> }
Dan Rogers - 08 Mar 2005 21:24 GMT
It won't give him the SOAP request or the HTTP headers - but it's close.
--------------------
>Message-ID: <2235632445925053619134@news.microsoft.com>
>From: Trevor Pinkney <tpinkney@cyence.com>
[quoted text clipped - 5 lines]
>Date: Mon, 21 Feb 2005 11:20:40 -0800
>NNTP-Posting-Host: z-f5-0-0-229-s1.gw1.tor1.sprint-canada.net
206.186.91.250
>Lines: 1
>Path:
TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP1
4.phx.gbl
>Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet.webservices:28225
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webservices
>
[quoted text clipped - 55 lines]
>>> return myXmlElement; //System.Xml.XmlElement
>>> }