Why do I need to set up the aspNetCompatibilityEnabled twice? - asp.net

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 = AspNetCompatibilityRequirementsMode.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.

Related

Can an IIS application pool be restricted to 1 working process and 1 thread?

I have to see if I can work around a known thread safety issue on third party component. The plan was to let an ASP.Net app to talk to the third party component via a WCF service, this was based on the assumption that I will be able to assign the WCF service to it's own application pool, restrict the pool to one working process and the working process to one thread. Requests to the service will have to wait for their turn, but that's OK because we expect them to require very little time and to be rare as well.
Problem is, I can't find anything that suggests how to achieve this part: "restrict the working process to one thread".
I have found a few useful pages, but no solution:
On IISforums, the discussion seem to suggest that I can achieve this in IIS 7+ but does not mention IIS6.
On MSDN Blogs and linked MSDN books chapter (can't put the link because I'm new here!) the discussion is mostly about what you can set via the machine.config file, which, if I'm understanding it correctly, is going to apply to all AppPools/Worker processes and is not what I'm trying to do, I would like to control what one single app can do, leaving the other applications untouched.
Questions:
Is it possible to achieve what I'm trying to do? (assign the WCF service to it's own application pool, restrict the pool to one working process and the working process to one thread" via IIS 6 configurations)
If not, can this be achieved programmatically somehow? For example, using locks or other threading-related tricks within my WCF service implementation.
It doesn't make much sense to me.. A web server have to be multithreaded by definition, because it must handle different income messages at the same time, if there is only one thread once in use any new request will fail.
What about to wrap the component in a class with a SynchonizationAttribute, so only one thread can access the component? Even if this will make your solution less scalable, at least it may work
http://msdn.microsoft.com/en-us/library/system.runtime.remoting.contexts.synchronizationattribute(v=vs.110).aspx

Using WIF without web.config

I need to create a web application that uses WIF to communicate with ADFS in order to login users. This web application supports multi-tenancy, accordingly, the same code base will be used to serve requests to site1.mydomain.com and site2.mydomain.com.
Currently, my WIF configuration is in the web.config file which is preventing me from achieving multi-tenancy. So I thought maybe there's a way to provide all the required WIF configuration through code by reading the host name from the request url and retrieving the tenant's configuration from the database instead of the web.config file.
Is that even possible? Any ideas or thoughts?
You migth get some ideas from this similar post :
how do i move federated configuration out of the web config
AFAIK the FederationConfigurationCreated is called only once per application. This means that you will need to "wire" things like a custom securitytokenhandler, cookiehandler, certificatvalidator etc that do their work based on the current context. I would personally consider all of this "doable" but it migth take you 1 to 2 months to get all the sharp edges out of it. I mean, writing a securitytokenhandler is doable but it will be simpler when you have done so before. You will need to dive really deep in WIF and want to consider whether that is what you want.
As an alternative (that you probably don't want) you migth consider a deployment per tenant. Depending on the number and volatility of tenants this migth or migth not be a good idea.

change applicationcontext from in code

I have a little problem. I hope someone can help me.
I'm developping an application for my thesis.
Now I have an application-context.properties.txt where I define:
host= (ip address)
port=8080
Now this is static and I change the ip address to the server I want to connect to.
But this isn't verry usefull for the user because he can't access that file.
Now is my question can I change this host ip address from in my flex code? And how do I do that.
Hope someone can help me.
Kind regards,
Thibault Heylen
Usually Configurations i.e services.xml embeds at compile time, this blog
Externalizing Service Configuration using BlazeDS and LCDS
pointed towards way to Externalizing Service Configuration,
hopes that works,
Looking at the documentation, the FlexXMLApplicationContext is just one example of an application context. Possibly, you can derive from it or the XMLApplicationContext to allow for runtime changes to configuration variables, if the context class doesn't support it already?
You won't be able to change the value in the XML file itself, since it is a compiled resource, but you should be able to extend SpringAS to do what you want at runtime.

Loading connection strings from class library in web application

I have a fairly straightforward problem that I imagine has a simple solution. However, it's not clear to me. Here's the problem:
I have a web application that references a class library. That class library needs to access the connection strings in the web.config. From what I've read, this shouldn't be a problem.
Here's the code that I'm using to access the connection strings:
Dim connectionStrings As ConnectionStringSettingsCollection = ConfigurationManager.ConnectionStrings
When I run this code in the web application, I get all of my connection strings back. However, when this exact same code is run in the class library (called from the web application), it reverts to the machine.config for some reason and gets the entry from there. i.e.
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
I'm not sure if it matters or not, but the web side of this is a WCF RIA services web site that backs a Silverlight application. I didn't see anything funny in the config that could justify this strange behavior. Any thoughts on why I'm seeing this behavior?
Thanks,
Matt
There's a "WebConfigurationManager" Class, I guess it may solve your problem.

Web application configuration settings - Which is the better place to store

I came across a case study few days early. It is related to a web application architecture.
Here is the scenario,
There is a single web service used by say 1000 web applications. This web service is hosted on a particular server. If web service hosting location is changed, how the other applications come to know about this change ?
Keeping it in web.config doesn't seems to be a feasible solution as we need to modify web.config files for all the applications.
Keeping these settings in a common repository and let all the applications use it for web-service address was came in my mind, but again there is a question of storing this common repository.
I am just curious to know about how this could be achieved with better performance.
Thanks in advance for any kind of suggestions.
do you have full access or control over all those web applications consuming that web service? if so, you could have a script or some custom code which updates all their web.config(s) at once. it seems too much work but in fact in this way you have more control and you could also, eventually, point to the new url only some applications and leave some others on another url.
the idea with the setting in a centralized database gives you faster update propagation which could also be bad in case of errors and then you have all applications referring to the same place and no way to split this. Then you have anyway to connect to a centralized database from all of them and maybe you should add a key to their web.config(s) with the connection string to that database, then, in case that database is not reachable or is down, the web applications will not be able to consume the web service simply because they cannot get the url of it.
I would go for the web config, eventually you could have a settings helper class that abstract the retrieval of that url so the UI or front end does not know from where that url comes from.
anyway, do you plan to change the url of a web service often? wouldn't be better to copy it to a new url but to also keep it available on the current url for a while?
another advantage of web.config approach is that everytime you update and save it the application is restarted while a change in a database might take a while to be detected in case you have some caching mechanism,
hope this helps.
Davide.

Resources