IIS 7记录Web服务方法

时间:2022-12-03 22:56:15

I have a web service (not a WCF service) hosted under IIS 7, the web service has two methods: method1, and method2.

我有一个在IIS 7下托管的Web服务(不是WCF服务),Web服务有两种方法:method1和method2。

I am looking to differentiate between the requests for method1, versus the requests for method2, without modifying the web service code.

我想在不修改Web服务代码的情况下区分method1的请求和方法2的请求。

Under the IIS 7 logs, I can see the requests to the web service, the web service URL gets logged under the "cs-uri-stem" field, but the "cs-uri-query" field is empty.

在IIS 7日志下,我可以看到对Web服务的请求,Web服务URL记录在“cs-uri-stem”字段下,但“cs-uri-query”字段为空。

Is there anyway to log the requests for the web service methods, without modifying the web service code?

无论如何都要记录Web服务方法的请求,而不修改Web服务代码?

3 个解决方案

#1


3  

You can log all incoming request inside various methods of the processing pipeline. For example, add a handler for BeginRequest in your Global.asax:

您可以在处理管道的各种方法中记录所有传入请求。例如,在Global.asax中为BeginRequest添加一个处理程序:

Application_BeginRequest( object sender, EventArgs e )
{
    HttpApplication app = (HttpApplication)sender;
    HttpContext ctx = app.Context;

    var requestUrl = ctx.Request.Url;

    // the uri should be of a form:
    // http://yoursite/theservice.asmx/MethodName
}

#2


1  

Years later, I've had to visit an ASMX with hundreds of methods and it's just not possible to convert to WCF. Here is an ASMX extension point that allows you to log the method name without visiting all methods. Here, I'm using log4net to log the method name, YMMV

多年以后,我不得不使用数百种方法访问ASMX,而且无法转换为WCF。这是一个ASMX扩展点,允许您在不访问所有方法的情况下记录方法名称。在这里,我使用log4net来记录方法名称YMMV

First, create a SoapExtension class:

首先,创建一个SoapExtension类:

namespace MyNamespace {
    public class WebMethodLogger : SoapExtension
    {
        private static readonly ILog _log = LogManager.GetLogger(typeof(WebMethodLogger));

        public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
        {
            return null; //No state
        }

        public override object GetInitializer(Type serviceType)
        {
            return null; //No state
        }

        public override void Initialize(object initializer)
        {
            //Do nothing
        }

        public override void ProcessMessage(SoapMessage message)
        {
            if (message.Stage == SoapMessageStage.AfterDeserialize)
                _log.Debug(message.MethodInfo.MethodInfo.Name);
        }
    }
}

Then, register the extension in your web.config:

然后,在web.config中注册扩展名:

<system.web>
...
    <webServices>
        <soapExtensionTypes>
            <add type="MyNamespace.WebMethodLogger, MyAssembly"
                 priority="1"
                 group="High" />
        </soapExtensionTypes>
    </webServices>
...
</system.web>

#3


-2  

Here is the oficial article from microsoft: http://support.microsoft.com/kb/313437

以下是来自microsoft的官方文章:http://support.microsoft.com/kb/313437

1- Start Internet Information Services (IIS) Manager.

1-启动Internet信息服务(IIS)管理器。

2- Expand ServerName, and then expand Web Sites or FTP Sites. Right-click the Web site or the FTP site where you want to enable logging, and then click Properties.

2-展开ServerName,然后展开“网站”或“FTP站点”。右键单击要在其中启用日志记录的网站或FTP站点,然后单击“属性”。

3- Click the Web Site tab, or click the FTP Site tab.

3-单击“网站”选项卡,或单击“FTP站点”选项卡。

4- Click to select the Enable logging check box.

4-单击以选中“启用日志记录”复选框。

5- In the Active log format box, click the format that you want to use.

5-在“活动日志格式”框中,单击要使用的格式。

6- Click Properties, and then specify the settings that you want. For example, if you use W3C Extended log file format, follow these steps:

6-单击“属性”,然后指定所需的设置。例如,如果您使用W3C扩展日志文件格式,请按照下列步骤操作:

a. If you are running IIS 6.0, click the General tab. If you are running IIS 5.0 or IIS 4.0, click the General Properties tab. Specify the schedule that you want to use to create new log files. For example, to create a new log file every day, click Daily.

一个。如果您运行的是IIS 6.0,请单击“常规”选项卡。如果您运行的是IIS 5.0或IIS 4.0,请单击“常规属性”选项卡。指定要用于创建新日志文件的计划。例如,要每天创建新的日志文件,请单击“每日”。

b. If you want to use local time, click to select the Use local time for file naming and rollover check box.

湾如果要使用本地时间,请单击以选中“使用本地时间进行文件命名和翻转”复选框。

Note Midnight local time is used for all log file formats except W3C Extended log file format. By default, W3C Extended log file format uses midnight Coordinated Universal Time (Greenwich Mean Time). To use midnight local time, click to select the Use local time for file naming and rollover check box.

注意午夜本地时间用于除W3C扩展日志文件格式之外的所有日志文件格式。默认情况下,W3C扩展日志文件格式使用午夜协调世界时(格林威治标准时间)。若要使用午夜本地时间,请单击以选中“使用本地时间进行文件命名和翻转”复选框。

c. If you are running IIS 6.0, click the Advanced tab. If you are running IIS 5.0 or IIS 4.0, click the Extended Properties tab.

C。如果您运行的是IIS 6.0,请单击“高级”选项卡。如果您运行的是IIS 5.0或IIS 4.0,请单击“扩展属性”选项卡。

d. Specify the options that you want. For example, specify the properties that are listed in the "Customize the data" section. Click OK.

d。指定所需的选项。例如,指定“自定义数据”部分中列出的属性。单击确定。

e. Click OK.

即单击确定。

#1


3  

You can log all incoming request inside various methods of the processing pipeline. For example, add a handler for BeginRequest in your Global.asax:

您可以在处理管道的各种方法中记录所有传入请求。例如,在Global.asax中为BeginRequest添加一个处理程序:

Application_BeginRequest( object sender, EventArgs e )
{
    HttpApplication app = (HttpApplication)sender;
    HttpContext ctx = app.Context;

    var requestUrl = ctx.Request.Url;

    // the uri should be of a form:
    // http://yoursite/theservice.asmx/MethodName
}

#2


1  

Years later, I've had to visit an ASMX with hundreds of methods and it's just not possible to convert to WCF. Here is an ASMX extension point that allows you to log the method name without visiting all methods. Here, I'm using log4net to log the method name, YMMV

多年以后,我不得不使用数百种方法访问ASMX,而且无法转换为WCF。这是一个ASMX扩展点,允许您在不访问所有方法的情况下记录方法名称。在这里,我使用log4net来记录方法名称YMMV

First, create a SoapExtension class:

首先,创建一个SoapExtension类:

namespace MyNamespace {
    public class WebMethodLogger : SoapExtension
    {
        private static readonly ILog _log = LogManager.GetLogger(typeof(WebMethodLogger));

        public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
        {
            return null; //No state
        }

        public override object GetInitializer(Type serviceType)
        {
            return null; //No state
        }

        public override void Initialize(object initializer)
        {
            //Do nothing
        }

        public override void ProcessMessage(SoapMessage message)
        {
            if (message.Stage == SoapMessageStage.AfterDeserialize)
                _log.Debug(message.MethodInfo.MethodInfo.Name);
        }
    }
}

Then, register the extension in your web.config:

然后,在web.config中注册扩展名:

<system.web>
...
    <webServices>
        <soapExtensionTypes>
            <add type="MyNamespace.WebMethodLogger, MyAssembly"
                 priority="1"
                 group="High" />
        </soapExtensionTypes>
    </webServices>
...
</system.web>

#3


-2  

Here is the oficial article from microsoft: http://support.microsoft.com/kb/313437

以下是来自microsoft的官方文章:http://support.microsoft.com/kb/313437

1- Start Internet Information Services (IIS) Manager.

1-启动Internet信息服务(IIS)管理器。

2- Expand ServerName, and then expand Web Sites or FTP Sites. Right-click the Web site or the FTP site where you want to enable logging, and then click Properties.

2-展开ServerName,然后展开“网站”或“FTP站点”。右键单击要在其中启用日志记录的网站或FTP站点,然后单击“属性”。

3- Click the Web Site tab, or click the FTP Site tab.

3-单击“网站”选项卡,或单击“FTP站点”选项卡。

4- Click to select the Enable logging check box.

4-单击以选中“启用日志记录”复选框。

5- In the Active log format box, click the format that you want to use.

5-在“活动日志格式”框中,单击要使用的格式。

6- Click Properties, and then specify the settings that you want. For example, if you use W3C Extended log file format, follow these steps:

6-单击“属性”,然后指定所需的设置。例如,如果您使用W3C扩展日志文件格式,请按照下列步骤操作:

a. If you are running IIS 6.0, click the General tab. If you are running IIS 5.0 or IIS 4.0, click the General Properties tab. Specify the schedule that you want to use to create new log files. For example, to create a new log file every day, click Daily.

一个。如果您运行的是IIS 6.0,请单击“常规”选项卡。如果您运行的是IIS 5.0或IIS 4.0,请单击“常规属性”选项卡。指定要用于创建新日志文件的计划。例如,要每天创建新的日志文件,请单击“每日”。

b. If you want to use local time, click to select the Use local time for file naming and rollover check box.

湾如果要使用本地时间,请单击以选中“使用本地时间进行文件命名和翻转”复选框。

Note Midnight local time is used for all log file formats except W3C Extended log file format. By default, W3C Extended log file format uses midnight Coordinated Universal Time (Greenwich Mean Time). To use midnight local time, click to select the Use local time for file naming and rollover check box.

注意午夜本地时间用于除W3C扩展日志文件格式之外的所有日志文件格式。默认情况下,W3C扩展日志文件格式使用午夜协调世界时(格林威治标准时间)。若要使用午夜本地时间,请单击以选中“使用本地时间进行文件命名和翻转”复选框。

c. If you are running IIS 6.0, click the Advanced tab. If you are running IIS 5.0 or IIS 4.0, click the Extended Properties tab.

C。如果您运行的是IIS 6.0,请单击“高级”选项卡。如果您运行的是IIS 5.0或IIS 4.0,请单击“扩展属性”选项卡。

d. Specify the options that you want. For example, specify the properties that are listed in the "Customize the data" section. Click OK.

d。指定所需的选项。例如,指定“自定义数据”部分中列出的属性。单击确定。

e. Click OK.

即单击确定。