How do I register a connection with a WebService running on IIS 6.0?

I am running ASP.NET WebService on IIS 6.0 which shows a lot of HTTP 500 (probably only WebService exceptions) inside a log on %systemroot%\System32\LogFiles\W3SVC1

a clients site.

Is it possible to register the content of these HTTP responses and there requests without changing the WebService using IIS or a plug-in for IIS?

I was thinking about using Wireshark or Fiddler to sniff HTTP traffic, but I'd rather just enable the option inside IIS to force it to log a message (this shouldn't be hard, since it logs the requested urls anyway)

+2


a source to share


2 answers


Create an HTTPModule and configure it in ASP.NET config. You don't need to modify the existing web service code (you don't even need sources), you just configure the HTTPModule in your Web.config.

In the HTTPModule, listen for events such as BeginRequest and EndRequest and you should be able to log in and out of the web service.

If you need to catch exceptions thrown in a web service, you can catch the Error event as described here and here .



Update:

According to this page, you cannot use the error events approach with web services, since web service errors are not routed to the Error event. Microsoft suggests using SOAP Extensions to log web service errors.

+3


a source


We did this before using log4net . Here are the high-level steps:

Create log4net section in web.config file

<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>

      

and...

...
</system.web>
  <log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender,log4net">
      <param name="File" value="c:\mysvc.log" />
      <param name="AppendToFile" value="true" />
      <param name="MaxSizeRollBackups" value="10" />
      <param name="MaximumFileSize" value="1000000" />
      <param name="RollingStyle" value="Size" />
      <param name="StaticLogFileName" value="true" />
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
      </layout>
    </appender>
    <!-- Setup the root category, add the appenders and set the default priority -->
    <root>
      <level value="DEBUG" />
      <!--<priority value="DEBUG" />-->
      <appender-ref ref="RollingLogFileAppender" />
    </root>
  </log4net>

      

...

In your call to Global.asax.cs, call the log4net Configure () function



protected void Application_Start(Object sender, EventArgs e)
{
            log4net.Config.DOMConfigurator.Configure();
}

      

At the top of your webservice .cs file declare a log4net ILog instance

public class MyService : System.Web.Services.WebService {
{
   private static readonly ILog log = LogManager.GetLogger(typeof(MyService));

      

In your web service methods, exclude traps and register them

[WebMethod]
public void DoSomething()
{
  try
  {
     // business logic
  }
  catch(Exception ex)
  {
     log.Error("Something bad happened", ex);
     throw;
  }
}

      

After these steps in the above example, all exceptions will show up in c: \ mysvc.log

+4


a source







All Articles