简体   繁体   English

WCF多个服务在同一配置中具有相同合同

[英]WCF multiple services same contract in same Config

Im trying to host to different service implementations of the same contract: 我试图托管同一合同的不同服务实现:

模型

The reason is that need a dummy implementation for out-of-the-house testing. 原因是需要用于外部测试的虚拟实现。

Im trying to host both in the same WindowsService: 我试图将两者都托管在同一个WindowsService中:

    private ServiceHost _host;
    private ServiceHost _dummy;
    protected override void OnStart(string[] args)
    {
        _host = new ServiceHost(typeof(Service));
        _host.Open();

 //trying to avoid the app.config beeing used - because its already been hoste by _host
        _dummy = new ServiceHost(typeof(TestDummyService));
        _dummy.Description.Endpoints.Clear();
        _dummy.AddServiceEndpoint(typeof(IService), 
                                   new WebHttpBinding(),
                                  @"<link>/Dummy.svc/");
        _dummy.ChannelDispatchers.Clear();
        _dummy.Open();
     }

This is the config file: 这是配置文件:

  <system.serviceModel>
    <services>
      <service name="namespace.Service">
        <host>
          <baseAddresses>
            <add baseAddress="<link>/Service.svc"/>
          </baseAddresses>
        </host>
        <endpoint address="" 
                  binding="webHttpBinding" 
                  contract="namespace.IService" 
                  behaviorConfiguration="web" />

        <endpoint address="/mex" 
                  binding="mexHttpBinding" 
                  contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors >
        <behavior>
          <serviceMetadata httpGetEnabled="true"
                           httpGetUrl="<link>/Service.svc/About" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name ="web">
          <webHttp />         
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

The ChannelDispatcher at /Service.svc/About with Contracts 'IHttpGetHelpPageAndMetadataContract' is unable to open. /Service.svc/About中带有合同'IHttpGetHelpPageAndMetadataContract'的ChannelDispatcher无法打开。

any help is appreciated. 任何帮助表示赞赏。

Update 1 My goal is to have 2 different implementations of the same contract ( IService ) hosted in one WindowsService. 更新1我的目标是在一个WindowsService中托管同一合同( IService )的2个不同实现。

I would also like to configure both of them in the config file. 我也想在配置文件中配置它们两个。

Well i would like to know what's the business scenario. 好吧,我想知道什么是业务场景。 All I guess is, the client should not know the implementation, its just the URL of the service would indicate (or route) to the implementation. 我只想知道,客户端不应该知道实现,它只是服务的URL会指示(或路由)实现。

Kindly clarify. 请澄清。


Refer to this existing post and let me know if it makes sense. 请参阅此现有帖子 ,让我知道是否有意义。


The above post is hinting the implementation, refer to this post for deployment details. 上面的帖子暗示了实现,有关部署的详细信息,请参考该帖子

so i found out, that even thow the testdummy service was added programatic, it still got the service metadatabehavior. 所以我发现,即使将testdummy服务添加为程序性的,它仍然具有服务元数据行为。

My solution was to not make the dehavior default - given it at name: 我的解决方案是不将行为作为默认值-为其指定名称:

app.config: 的app.config:

<service name="namespace.Service" behaviorConfiguration="someName">

//.. later: // ..稍后:

    <behavior name="someName">
      <serviceMetadata httpGetEnabled="true"
                       httpGetUrl="<link>/Service.svc/About" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>

The rest of the code, statyed the same 其余代码,声明相同

Can't you add another endpoint and fill in the adress with a distinct name: 您不能添加另一个端点并用一个唯一的名称填写地址:

<endpoint address="/SecondService" 
              binding="webHttpBinding2" 
              contract="namespace.IService" 
               />

Url becomes /Service.svc/SecondService 网址变成/Service.svc/SecondService

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在WCF中托管具有2种不同配置的相同合同作为2种服务? - How to host same contract with 2 different configurations as 2 services in WCF? 如何使用具有相同合同和绑定的动态端点创建多个wcf服务实例而不保存在app.config中? - how to create multiple instance of wcf service using dynamic endpoint with same contract and binding without saving in app.config? 在 WCF 和 Castle Windsor 中注册同一合约的多个端点 - Register multiple endpoints of same contract in WCF and Castle windsor 具有相同对象的WCF服务 - WCF services with the same object 多个Windows服务使用具有多个端点的同一WCF? - multiple windows services using same wcf with multiple endpoints? WCF Web服务 - 在同一服务器上进行多跳模拟 - WCF Web Services - Multiple Hop impersonation on the same server 使用ninject.extension.wcf selfhost在同一baseAddress上提供多种服务 - Multiple services on same baseAddress using ninject.extension.wcf selfhost 来自同一WCF服务主机中不同服务的多个终结点 - Multiple endpoints from different services in the same WCF service host 多个服务器实例中的 WCF 相同服务合同 - WCF Same Service Contract in several Server Instances 在一个配置中配置多个WCF绑定或服务 - Configure multiple WCF bindings or services in one config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM