【发布时间】:2013-12-13 20:54:04
【问题描述】:
我想写出 SOAP Web 服务的传入请求。原来我的 Application_BeginRequest 事件没有触发。它在 IIS6 和 Windows 2003 上运行,因此其他地方推荐的配置更改没有任何效果。
protected void Application_BeginRequest(object sender, EventArgs e) { 尝试 { byte[] inputBytes = new byte[HttpContext.Current.Request.ContentLength];
HttpContext.Current.Request.InputStream.Position = 0;
HttpContext.Current.Request.InputStream.Read(inputBytes, 0, inputBytes.Length);
string requestString = ASCIIEncoding.ASCII.GetString(inputBytes);
Logger.Write("input: " + Convert.ToString(inputBytes.Length), Global.LOGGER_EVENT_SOURCE, 0, 0, TraceEventType.Warning);
using (var writer = new StreamWriter(@"c:\inetpub\wwwroot\requests\testfile - " + DateTime.Now.ToString("MMddYYYYhhmmssffff") + ".xml"))
{
writer.Write(requestString);
writer.Close();
}
// Reset stream pointer to beginning.
HttpContext.Current.Request.InputStream.Position = 0;
}
catch (Exception ex)
{
// Error handling; omitted here.
}
}
如果我只是把它放在被调用的 Web 服务方法中,代码“几乎”就可以工作;文件已创建,但请求的内容长度为“0”。
感谢您的建议。
【问题讨论】:
标签: asp.net web-services httprequest global-asax