IIS7 / WPAS: multiple WCF services in the same AppDomain?

If my WCF services host in IIS7 or WPAS, is it possible to load two or more services into the same AppDomain so that they can share static variables?

+4
source share
3 answers

Of course, you can provide as many endpoints in a web application as you want (even for different WCF services). This should not be limited to either IIS or WPAS.

This will allow you to access any shared data . Although I would usually advise against using static variables to exchange information (but, of course, I do not know your requirements).

+5
source

Sure. In Visual Studio, just add another WCF service element. IIS will run both services in the same AppDomain. In this example, I first created a library with only the following interface definition:

namespace ServiceInterface { [ServiceContract] public interface IClass { [OperationContract] string GetMessage(); } } 

Then I created a web application in VS and added two services: MyService and Service2 , which both implement IClass . This is my section of the web.config file for serviceModel

  <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="WebService1.MyServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> <behavior name="WebService1.Service2Behavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="WebService1.MyServiceBehavior" name="WebService1.MyService"> <endpoint address="" binding="wsHttpBinding" contract="ServiceInterface.IClass"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> <service behaviorConfiguration="WebService1.Service2Behavior" name="WebService1.Service2"> <endpoint address="" binding="wsHttpBinding" contract="ServiceInterface.IClass"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> </system.serviceModel> 

In a client application, the configuration data may look like this:

 <client> <endpoint address="http://mymachinename.local/MyService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IClass" contract="ServiceReference1.IClass" name="WSHttpBinding_IClass"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="http://mymachinename.local/Service2.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IClass1" contract="ServiceReference2.IClass" name="WSHttpBinding_IClass1"> <identity> <dns value="localhost" /> </identity> </endpoint> </client> 
+2
source

Yes, you can do this in both IIS and WPAS. But the only way to do this is to collect both services in one assembly, AFAIK.

0
source

All Articles