2013-02-08 43 views
2

我試着去主機到同一合同的不同服務實現相同的合同。WCF多個服務中相同的配置

我試着在同一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(); 
    } 

這是配置文件:

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

在/Service.svc/About與合同 'IHttpGetHelpPageAndMetadataContract' 的ChannelDispatcher無法打開。

任何幫助表示讚賞。

更新1 我的目標是在一個WindowsService中託管同一合同(IService)的2個不同實現。

我也想在配置文件中配置它們兩個。

回答

0

所以我發現,即使是測試服務添加了programatic,它仍然得到了服務metadatabehavior。

我的解決辦法是不使dehavior默認 - 在名字給它:

的app.config:

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

// ..後來:

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

剩下的代碼statyed相同

0

您不能添加另一個端點並以不同的名稱填充地址:

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

網址將成爲/Service.svc/SecondService

+0

hi - thnks的反饋。沒有不幸,我不能。因爲端點不讓我決定我使用什麼實現。這是在服務標籤中指定的:'' – 2013-02-08 12:41:22

1

嗯,我想知道什麼是業務場景。我猜想,客戶端不應該知道實現,它只是服務的URL將指示(或路由)到實現。

請澄清。


請參閱本現有post,讓 我知道,如果這是有道理的。


上述職位暗示的實施,請參閱本post部署細節。

+0

感謝您的反饋。我已更新問題 – 2013-02-08 13:31:45

+0

鏈接反之亦然。我只有一份合同,但該合同有多個實施。鏈接也沒有提供任何有關如何託管darn事情的信息:)但是,感謝您的反饋 – 2013-02-08 22:16:04

+0

在上面的文章中,只有1個合同和2個實現,我不知道爲什麼它沒有幫助你。我編輯了答案並添加了一個鏈接。希望它有幫助... – Wali 2013-02-09 05:06:53