A multi-service contract at one C # wcf endpoint

I have a domain called cmsmanagement , but it has several objects. I create a service for each object in this domain. You can see here:

enter image description here

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

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> 
0
source share
1 answer

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

In short, this can be done programmatically 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, by adding a link, you can open your services with this behavior.

+1
source

All Articles