Why do I need to set up the aspNetCompatibilityEnabled twice?
Could anyone please explain why when creating a WCF webservice in which you want to use HttpContext.Current.Items
you need to add some code in 2 places?
One in the webservice itself ([AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibili开发者_开发百科tyRequirementsMode.Required)]
) and one in the web.config file (<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
)?
A colleague of mine just had all his webservice calls failing. He had the web.config setup missing and asked me why. I tried to explain, but I'm not sure if I was able to :)
I think it has to do with the separation of the webservice code and the place where the webservice gets hosted. The webservice itself says that it needs that compatibility mode. It is then also needed to setup the hosting environment to say that it should run in that compatibility mode. Isn't this basically the point? He still had a question: "but, if the service uses that attribute, should it not be automaticly ?"
The first tells WCF that aspcompat must be enabled and the second enables it. You should be able to do without the first.
This forces the person configuring the WCF service to use the right config.
MS designed this with the idea that the person configuring the service might be someone else that the person that made it.
To answer his last question. When you add attributes to your service you're not configuring the host, you're demanding how the host should be configured. The configuring happens on the host.
精彩评论