IIS7 / WPAS: Multiple WCF services in same AppDomain?

非 Y 不嫁゛ 提交于 2020-01-14 10:24:05

问题


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?


回答1:


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




回答2:


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>



回答3:


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.



来源:https://stackoverflow.com/questions/333557/iis7-wpas-multiple-wcf-services-in-same-appdomain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!