目前,我正在将SOAP请求的响应序列化到本地磁盘上的XML文件中。用户可以在运行初始请求后随时查看XML的内容,因此我需要将XML存储在某处。我正在构建的应用程序将在Azure Web Apps上运行,而且从我收集的内容中,我无法写入这些服务器上的磁盘。所以接下来最好的事情是在我的数据库中创建一个简单的表并存储序列化的XML。我的问题是,我无法使用System.XML.XmlSerializer.Serialize
序列化XML,因为该方法需要StreamWriter,并且无法访问文件系统,我无法初始化System.IO.StreamWriter
。
我的序列化方法如下所示:
/* Simplified SOAP request / response */
SoapClient client = new SoapClient();
SoapResponse response = client.GetReport(soapRequest); //soapRequest = valid soap envelope
StreamWriter stWriter = null;
XmlSerializer xmlSerializer;
string filePath = @"C:\ReportXml\reportName.xml"
xmlSerializer = new XmlSerializer(response.GetType());
stWriter = new StreamWriter(filePath);
xmlSerializer.Serialize(stWriter, response);
这不适用于Azure。有什么工作吗?有些方法可以在不将其写入磁盘的情况下序列化XML吗?
答案 0 :(得分:1)
/* Simplified SOAP request / response */
SoapClient client = new SoapClient();
SoapResponse response = client.GetReport(soapRequest); //soapRequest = valid soap envelope
StreamWriter stWriter = null;
XmlSerializer xmlSerializer;
var stream = new MemoryStream();
xmlSerializer = new XmlSerializer(response.GetType());
stWriter = new StreamWriter(stream);
xmlSerializer.Serialize(stWriter, response);