при публикации сообщения xml от клиента в службу WCF, когда при получении сохранения файла xml мы теряли корневой элемент (например, для тега) в содержимом xml
Код сервера:
[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
=============================================== ============
Клиент HTTP публикует данные
вход ::
<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>
"В документе XML разрешен только один элемент верхнего уровня. Ресурс обработки ошибок"
отсутствует тег ROOT в a.xml на сервере
<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>