views:

340

answers:

5

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
A: 

I host my WCF service by IIS 7. There is no such kind of problem. What's the version of your IIS. If it is old version, I think you need to do some configurations.

Jeffrey
I am using IIS7. I have also installed AppFabric
DotnetDude
+1  A: 

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>
Kirk Broadhurst
If I turn off ASP.NET compatibility, then I get the "activation error" (message in my original post)
DotnetDude
In your original post you're talking about adding an attribute to the service which determines whether or not the service can run in AspCompatibilityMode. I'm talking about configuring the application - in your web config - so that the application does not use AspCompatibilityMode at all (and your attribute becomes redundant). My answer has been edited.
Kirk Broadhurst
A: 

Please try setting multipleSiteBindingsEnabled to be true in the ServiceHostingEnvironment. I am not an expert in WCF but after going through the question and reading a bunch of sites I think it would make sense since you are using both TCP and HTTP service endpoints.

Hope this helps.

Raja
A: 

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.

Tridus