when by posting the xml message from client to WCF service, when by getting save the xml file we lost the root element(for eg: tag) in the xml content
Server Code :
[ServiceContract(Namespace = "http://www.mydomain.com/testing")]
public interface Imyservice
{
[OperationContract]
[WebInvoke(UriTemplate = "data", Method = "POST" ,BodyStyle = WebMessageBodyStyle.Bare,RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]
Stream postdata(XmlElement input);
}
-------------------------------------------------------
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(Namespace = "http://www.mydomain.com/testing")]
[XmlRootAttribute(ElementName = "Message", IsNullable = false)]
public class myservice : Imyservice
{
public Stream postdata([XmlAnyElement]**XmlElement** input)
{
string str = input.InnerXml.ToString();
String filepath = "D:\\WebFiles\\temp\\a.xml";
FileStream fs = File.Create(filepath);
byte[] XMLBytes = new System.Text.UTF8Encoding(true).GetBytes(str);
fs.Write(XMLBytes, 0, XMLBytes.Length);
fs.Close();
-----
Encoding encoding = Encoding.GetEncoding("ISO-8859-1");
WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
byte[] returnBytes = encoding.GetBytes(pstrstring);
return new MemoryStream(returnBytes);
}
}
Binding : webHttpBinding
===========================================================
Client HTTP post the data
input ::
<message>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
</message>
" Only one top level element is allowed in an XML document. Error processing resource"
ROOT tag is missing in the a.xml in server
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>