13

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
7
  • Are you using an ASP.NET feature? If so, which one? Can it be removed?
    – Adam Fyles
    Mar 4, 2010 at 2:01
  • Not yet - so far (Not sure If I would use session or context in the future). Are you saying that if I dont use any asp.net feature, I should be able to switch off the AspNetCompatibility and still host it in a web host?
    – DotnetDude
    Mar 4, 2010 at 14:37
  • why dont you expose the service using a windows service? I think that first and second are impossible to make unless you use WAS. Mar 5, 2010 at 12:50
  • I wonder how they do it in the StockTrader sample app. I believe they support HTTP and nonHTTP bindings for services hosted on a Web app (not WAS)
    – DotnetDude
    Mar 5, 2010 at 15:48
  • Ok, I hosted the WCF service on Appfabric. I still cannot turn off the AspNetCompatibilityRequirements
    – DotnetDude
    Mar 5, 2010 at 20:30

4 Answers 4

7

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.

4

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>
2
  • If I turn off ASP.NET compatibility, then I get the "activation error" (message in my original post)
    – DotnetDude
    Mar 8, 2010 at 19:46
  • 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. Mar 8, 2010 at 21:00
1

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.

0

I encountered this issue as well.
it resulted from migrating some new code ,that referenced the System.Web namespace but didn't actually require it, into an existing WCF project. removing those using statements resolved the issue for me.

I expected to have to track down code that required that namespace but got lucky.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.