2010-12-10 69 views
0

我在WCF中使用DiscoveryEndpoints,但我注意到當發現服務並且聯繫DiscoveryEndpoint時,它實際上會導致創建服務的實例。我不想要這個。阻止DiscoveryEndpoint創建服務實例

這幾乎肯定與我使用自定義實例提供程序(以支持StructureMap)的事實有關 - 它將自定義InstanceProvider應用於每個EndpointDispatcher。

看來我只想爲合同實際上與服務實現匹配的端點應用自定義InstanceProvider。

任何想法?

回答

1

我覺得我的工作了......我只是忽視任何有IsSystemEndpoint集:

public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) 
    { 
     foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers) 
     { 
      ChannelDispatcher cd = cdb as ChannelDispatcher; 
      if (cd != null) 
      { 
       foreach (EndpointDispatcher ed in cd.Endpoints) 
       { 
        if (!ed.IsSystemEndpoint) // Ignore MEX etc 
         ed.DispatchRuntime.InstanceProvider = 
          new StructureMapInstanceProvider(serviceDescription.ServiceType); 
       } 
      } 
     } 
    } 
+0

謝謝你幫我。我不斷收到無法投射異常。 – Michael 2012-12-11 21:17:05