2013-12-13 41 views
0

我想寫出傳入的SOAP Web服務請求。原來,我的Application_BeginRequest事件沒有觸發。它運行在Windows 2003的IIS6 &上,因此其他地方推薦的配置更改沒有任何影響。Application_BeginRequest未觸發(不是URL重寫)

保護無效的Application_BeginRequest(對象發件人,EventArgs的) { 嘗試 { 字節[] inputBytes =新的字節[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'。

感謝您的任何建議。

回答

0

此問題最可能的原因是該網站未設置爲應用程序。

+0

我記得曾經有一個'網站'和'網絡應用程序'之間的區別,但我不認爲這已經存在了。我相信它是一個Web應用程序,但我會研究這一點,因爲它不是我在IDE或Web服務器上查看的內容。 –