WCF service with HttpContext

1.6k views Asked by At

I had a web service which I converted to wcf service with the same asmx extension. I have basicHttpbinding since my service talks to various clients like java, perl etc.

I had a validation which had HttpContext.Current in it. But I know this will not work in wcf service. I am trying to use RequestContext or OperationContext but am not able to do so. I tried to use

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]

but did not help. I am calling my service from soapUI for testing.

2

There are 2 answers

0
Ashish On BEST ANSWER

Ok, So I found the solution. There are quite some ways to get the HttpContext.Current context. Either we can use OperationContext or we can use the AspNetCompatibilityRequirements mode set to Allowed and aspNetCompatibilityEnabled set to true in web.config.

For my case where I had converted the asmx service to wcf service, I also had to modify the HttpHandler handler to remove and add asmx path to System.ServiceModel.Activation.HttpHandler.

0
sandip On

You would better to use the OperationContext while using WCF services. As you will always get the HttpContext.Current.Items is always Null which runs only while ASP.NET. So add the following code:-

OperationContext.Current.Extensions.Add(extension);