0

I have a domain called cmsmanagement but it has several entity .I create a service for each entity in this domain .as you can see here :

enter image description here

So if my clients want to call my service ,they have to add each entity service one by one .I want to have one endpoint for all these service ,For example if the client call this mydomain/cmsmanagementservice.svc .all these services are called .

Here is my webconfig :

<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>
Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180
  • What do you mean by "all this services called" ? In what manner they called? What arguments and functions called? If you want to interact with other services upon call to some service functions - you should use IoC pattern. Many frameworks, like Ninject support DI. – eocron May 24 '17 at 10:30
  • @eocron when the client click on add service reference they just add one endpoint address,and all other services(News,Filemanagemenet,Page) be added to client project – Ehsan Akbar May 24 '17 at 10:32
  • https://stackoverflow.com/questions/14336861/wcf-how-to-bind-multiple-service-contracts – Ehsan Akbar May 24 '17 at 12:14

1 Answers1

1

You can enable WS-Discovery feature in your project. More here: https://msdn.microsoft.com/en-us/us-us/library/dd456791(v=vs.110).aspx

In short, it can be done programmaticaly like this:

Uri baseAddress = new Uri(string.Format("http://{0}:8000/discovery/scenarios/calculatorservice/{1}/",  
        System.Net.Dns.GetHostName(), Guid.NewGuid().ToString()));  

// Create a ServiceHost for the CalculatorService type.  
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress))  
{  
    // add calculator endpoint  
    serviceHost.AddServiceEndpoint(typeof(ICalculator), new WSHttpBinding(), string.Empty);  

    // ** DISCOVERY ** //  
    // make the service discoverable by adding the discovery behavior  
    ServiceDiscoveryBehavior discoveryBehavior = new ServiceDiscoveryBehavior();  
    serviceHost.Description.Behaviors.Add(new ServiceDiscoveryBehavior());  

    // send announcements on UDP multicast transport  
    discoveryBehavior.AnnouncementEndpoints.Add(  
      new UdpAnnouncementEndpoint());  

    // ** DISCOVERY ** //  
    // add the discovery endpoint that specifies where to publish the services  
    serviceHost.Description.Endpoints.Add(new UdpDiscoveryEndpoint());  

    // Open the ServiceHost to create listeners and start listening for messages.  
    serviceHost.Open();  

    // The service can now be accessed.  
    Console.WriteLine("Press <ENTER> to terminate service.");  
    Console.ReadLine();  
}  

Then, when adding reference, you should be able to discover your services with such behaviors.

eocron
  • 6,885
  • 1
  • 21
  • 50