Aimal Khan
Aimal Khan

Reputation: 1019

Implementing PostSharp with Asmx Web Service

I'm currently trying to integrate postsharp with my asmx web service for the purpose of logging exceptions.

Here's my code for the Aspect perspective:

[Serializable]
public class LogPerformance : OnMethodBoundaryAspect
{
    public override void OnEntry(MethodExecutionArgs args)
    {
        string test = "test";
        base.OnEntry(args);
    }

    public override void OnExit(MethodExecutionArgs args)
    {
        string test = "test";
        base.OnExit(args);
    }

    public override void OnException(MethodExecutionArgs args)
    {
        string test = "test";
        base.OnException(args);
    }
}

while in my Service.cs class, i've the following web method:

[WebMethod(EnableSession = true)]
[SoapHeader("authentication")]
[LogPerformance]
public DataTable loginUser(string userName, string password)
{
    doStuff();
}

Coming straight to the point:

It is important to note that the same LogPerformance Class runs smoothly when integrated with:

The problem is when i use it with .asmx web service. A little nudge towards the right direction would be appreciated.

Upvotes: 2

Views: 188

Answers (1)

AlexD
AlexD

Reputation: 5101

The *.asmx web-services are supported by PostSharp. However, you need to pay attention whether your ASP.NET project is a Web Site or a Web Application (ASP.NET Web Site or ASP.NET Web Application?). Only Web Application projects are supported by PostSharp. For more information on compatibility you can also check Requirements and Compatibility.

You can convert your Web Site project to Web Application project by following the guidelines from the blog post Converting a Web Site Project to a Web Application Project. After the conversion you need to install PostSharp NuGet package into your project.

Upvotes: 1

Related Questions