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