WCF hosted in a Web application and compatibility mode
Asked Answered
A

4

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
Acinus answered 3/3, 2010 at 22:6 Comment(7)
Are you using an ASP.NET feature? If so, which one? Can it be removed?Homs
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?Acinus
why dont you expose the service using a windows service? I think that first and second are impossible to make unless you use WAS.Selfstarter
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)Acinus
Ok, I hosted the WCF service on Appfabric. I still cannot turn off the AspNetCompatibilityRequirementsAcinus
you can not use nonHTTP binding in IIS without WAS, that's why I say that your requirements are impossible, you need to host the services yourself.Selfstarter
Hosting the service on Appfabric is different from hosting on WAS?Acinus
M
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.

Mortar answered 25/3, 2010 at 11:58 Comment(0)
R
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>
Rms answered 8/3, 2010 at 7:13 Comment(2)
If I turn off ASP.NET compatibility, then I get the "activation error" (message in my original post)Acinus
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.Rms
O
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.

Oloroso answered 17/3, 2010 at 13:12 Comment(0)
P
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.

Photogenic answered 15/6, 2017 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.