Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF hosted in a Web application and compatibility mode

Tags:

.net

.net-3.5

wcf

I have a WCF service hosted in a web application (IIS). I need to expose 1 end point over wsHttp and the other over netTcp. I am on a IIS7 environment that makes it possible for me to host non HTTP based services. Anyways, when I browse the .svc file using a browser, I get the error:

The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application

By googling, I realized that WCF runs in two modes - Mixed and ASP.NET compatible. When I apply the attribute

[AspNetCompatibilityRequirements(
       RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 

However, it appears that once I apply this attribute to the Service Contract implementation, I cannot use a non HTTP binding.

How do I set it up so that:

  • I can support non HTTP endpoints
  • I can host the service on a Web app
  • I don't create multiple services one with aspnet compatibility turned on and the other turned off
like image 653
DotnetDude Avatar asked Mar 03 '10 22:03

DotnetDude


People also ask

Where is WCF service hosted?

WCF services can be hosted in any managed application. This is the most flexible option because it requires the least infrastructure to deploy. You embed the code for the service inside the managed application code and then create and open an instance of the ServiceHost to make the service available.

Can we use WCF in web application?

WCF is one of the new foundations in the Web Services world and was introduced by Microsoft. It can be hosted in a console application or in IIS and can be accessed using Console applications, WPF applications or even websites.

What is WCF hosting?

A WCF service can be hosted by using any ways given below, IIS Hosting. It stands for Internet Information Services. Its working model is similar to that of ASP.NET while hosting a WCF service. It uses the IIS features like recycling, idle shutdown, health monitoring and message based activation.

What are is types of hosting supported in WCF service?

There are three types of hosting environments for WCF services: IIS, WAS, and self-hosting. The term “self-hosting” refers to any application that provides its own code to initialize the hosting environment. This includes console, Windows Forms, WPF, and managed Windows services.


2 Answers

There's quite a lot going on here. First of all, unless you're actually using an ASP.net feature specifically, you should NOT use compatability mode. To turn that off, follow Kirk's suggestion, and also remove this line from your code:

[AspNetCompatibilityRequirements(
       RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

Compatability mode isn't required just to host a HTTP service, it's only if you want to use ASP.net features that aren't in WCF (or need to port up an older asmx service to WCF without changing other code).

The second problem is hosting a non HTTP binding using IIS. That only works in IIS 7, and only using WAS. ASP.net compatability will NOT work with a non HTTP binding, because ASP.net requires HTTP.

So what you're trying to do is impossible so long as compatability mode is enabled. Remove it, and then things should work.

like image 58
Tridus Avatar answered Sep 28 '22 04:09

Tridus


At a guess, you have an ASP.NET compatibility setting turned on for your IIS application. This link seems to be related.

I would suggest you turn off ASP.NET compatibility mode. I have run net.tcp and basicHttp endpoints from the same application in IIS without problem.

edit: This is the configuration change you need to make / check (from the provided link). The value should be changed from 'false' to 'true'.

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled=”true” />
</system.serviceModel>
like image 41
Kirk Broadhurst Avatar answered Sep 28 '22 04:09

Kirk Broadhurst