IIS7 / WPAS: Multiple WCF services in same AppDomain?

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

Answers


Sure you can expose as many Endpoints within a Web Application as you want (even of different WCF Services). This should not be limited to either IIS or WPAS.

Doing so will enable you to access any kind of shared data. Even though I would normally advise against using static variables to share information (But of course I don't know your requirements).


Sure. In Visual Studio, simply add another WCF Service item. 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();
    }
}

I then created a web application in VS and added two services: MyService and Service2 which both implement IClass. This is my web.config file section 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 the client application, your configuration information might look like:

<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>

Yes you can do it in both IIS and WPAS. But the only way of doing that is compiling both services in the same assembly, AFAIK.


Need Your Help

Direct memory access of C++ DLL in C#

c# c++ dll pinvoke

I have searched stackoverflow for this problem but didn't find this exact one. In particular, I've found a ton of questions regarding retrieving C++ string references (char**) when the C# side is

How do you fix Google OAuth API - (403) There is a per-IP or per-Referer restriction configured on your API key

console google-api google-oauth

I have recently moved a project over to another server. The domain name is the same, it has just been pointed to the new server. The URL is exactly the same. Since moving the project over however I...