Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用global.asax或Ihttmodule记录Xml_C#_Asp.net_Web Services_Httprequest_Httpresponse - Fatal编程技术网

C# 使用global.asax或Ihttmodule记录Xml

C# 使用global.asax或Ihttmodule记录Xml,c#,asp.net,web-services,httprequest,httpresponse,C#,Asp.net,Web Services,Httprequest,Httpresponse,在web服务中,我需要记录每一个请求,这些请求都是xml格式的。 问题是,每当我试图将数据记录到文本文件中时,我都会得到一些xml字符的unicode值(我想是这样)。你能帮我写正确的文字吗。现在,我的XMl文件如下所示: <?xml version="1.0" encoding="utf-8" ?> <Fields> <Field> <DealeCode>C001</DealeCode> <I

在web服务中,我需要记录每一个请求,这些请求都是xml格式的。 问题是,每当我试图将数据记录到文本文件中时,我都会得到一些xml字符的unicode值(我想是这样)。你能帮我写正确的文字吗。现在,我的XMl文件如下所示:

<?xml version="1.0" encoding="utf-8" ?>
  <Fields>
    <Field>
      <DealeCode>C001</DealeCode>
      <IMEI>158518121</IMEI>
      <DealerName>Mohan Sales</DealerName>
      <UploadDate>17/10/2014</UploadDate>
    </Field>
  </Fields>

  System.IO.StreamReader reader = new System.IO.StreamReader(HttpContext.Current.Request.InputStream);
  string bodyText = reader.ReadToEnd();
  reader.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);

  System.IO.File.WriteAllText(@"D:\LogFile.txt", bodyText);

C001
158518121
磨憨销售
17/10/2014
System.IO.StreamReader reader=新的System.IO.StreamReader(HttpContext.Current.Request.InputStream);
字符串bodyText=reader.ReadToEnd();
reader.BaseStream.Seek(0,System.IO.SeekOrigin.Begin);
System.IO.File.WriteAllText(@“D:\LogFile.txt”,bodyText);
下面是我的日志文件在编写xml后的样子

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <HelloWorld xmlns="http://tempuri.org/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <xmlData>
      <?xml version="1.0" encoding="utf-8" ?>
        <Fields>
          <Field>
            <DealeCode>C001</DealeCode>    
            <IMEI>158518121</IMEI>    
            <DealerName>Mohan Sales</DealerName>    
            <UploadDate>17/10/2014</UploadDate>  
          </Field>  
        </Fields>
      </xmlData>
    </HelloWorld>
  </s:Body>
</s:Envelope>

C001
158518121
磨憨销售
17/10/2014  

但是,当我试图使用XDocument保存日志文件时,它会显示非法字符。请在此提供帮助。

我的日志文件输出已被审阅者更改,这似乎是他不应该做的。如果网站在发布文件时已询问此问题,我故意使用未格式化的xml,因为这是我的实际结果

为了清楚地说明这一点,我将使用以下字符 <; &燃气轮机;
&XlgD;等等

我已经解决了这个问题。