一个端点c#wcf中的多服务契约

一个端点c#wcf中的多服务契约,c#,web-services,wcf,C#,Web Services,Wcf,我有一个名为cmsmanagement的域,但它有多个实体。我为此域中的每个实体创建了一个服务。如您所见: 因此,如果我的客户端想要调用我的服务,他们必须逐个添加每个实体服务。我希望所有这些服务都有一个端点,例如,如果客户端调用mydomain/cmsmanagementservice.svc。所有这些服务都被调用 这是我的网络配置: <configuration> <appSettings> <add key="aspnet:UseTaskFrie

我有一个名为
cmsmanagement
的域,但它有多个实体。我为此域中的每个实体创建了一个服务。如您所见:

因此,如果我的客户端想要调用我的服务,他们必须逐个添加每个实体服务。我希望所有这些服务都有一个端点,例如,如果客户端调用mydomain/cmsmanagementservice.svc。所有这些服务都被调用

这是我的网络配置:

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

您可以在项目中启用WS-Discovery功能。详情如下:

简言之,可以按如下方式编程:

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();  
}  
uribaseaddress=newuri(string.Format(“http://{0}:8000/discovery/scenarios/calculatorservice/{1}/”,
System.Net.Dns.GetHostName(),Guid.NewGuid().ToString());
//为CalculatorService类型创建ServiceHost。
正在使用(ServiceHost ServiceHost=新ServiceHost(typeof(CalculatorService),baseAddress))
{  
//添加计算器端点
AddServiceEndpoint(typeof(ICalculator),new WSHttpBinding(),string.Empty);
//**发现**//
//通过添加发现行为使服务可发现
ServiceDiscoveryBehavior discoveryBehavior=新ServiceDiscoveryBehavior();
serviceHost.Description.Behaviors.Add(新ServiceDiscoveryBehavior());
//在UDP多播传输上发送通知
discoveryBehavior.AnnouncementEndpoints.Add(
新的UDPANNounceEndpoint());
//**发现**//
//添加指定在何处发布服务的发现端点
serviceHost.Description.Endpoints.Add(新的UdpDiscoveryEndpoint());
//打开ServiceHost以创建侦听器并开始侦听消息。
Open();
//现在可以访问该服务。
控制台。WriteLine(“按以终止服务”);
Console.ReadLine();
}  

然后,在添加引用时,您应该能够发现具有此类行为的服务。

您所说的“所有这些服务都被调用”是什么意思?他们以什么方式打电话?什么参数和函数被调用?如果您希望在调用某些服务功能时与其他服务交互,则应该使用IoC模式。许多框架,如Ninject support DI。@eocron当客户端单击“添加服务引用”时,它们只添加一个端点地址,所有其他服务(新闻、Filemanagemenet、页面)都将添加到客户端项目中。我想在webconfig中绑定这两个contract和svc