2010-11-23 5 views
0

모든 인터페이스가 자체 인터페이스를 구현하는 여러 개의 wcfClient (웹 참조로 설계됨)를 가지며 차례로 다른 인터페이스를 상속합니다.WCFClient 캐스팅 (또는 일반 콜렉션 사용)

내가 그렇게하는 대신이 일을, 모든 웹 서비스가 상속하는 인터페이스의 메소드를 호출 할 ... 내가

switch (service) 
     { 
     case "DVSSync": 
            DVSSync.WcfDVSSyncClient dvsSyncClient = new DVSSync.WcfDVSSyncClient("BasicHttpBinding_IWcfDVSSync1"); 

    GenericClient wcfClient = (GenericClient)dvsSyncClient; 


            break; 

           case "DataInserter": 
            DataInserter.WcfDataInserterClient dataInserterClient = new DataInserter.WcfDataInserterClient("BasicHttpBinding_IWcfDataInserter1"); 

    GenericClient wcfClient = (GenericClient)dataInserterClient ; 

            break; 

     } 

            dataRow["URI"] = wcfClient.Endpoint.Address.ToString(); 
            dataRow["ServiceUptime"] = wcfClient.ServiceUptime(); 
            dataRow["Version"] = wcfClient.Version(); 

            wcfClient.Close(); 

에 비슷한 일을하고 싶지

case "DVSSync": 
         DVSSync.WcfDVSSyncClient dvsSyncClient = new DVSSync.WcfDVSSyncClient("BasicHttpBinding_IWcfDVSSync1"); 

         dataRow["URI"] = dvsSyncClient.Endpoint.Address.ToString(); 
         dataRow["ServiceUptime"] = dvsSyncClient.ServiceUptime(); 
         dataRow["Version"] = dvsSyncClient.Version(); 

         dvsSyncClient.Close(); 
         break; 

        case "DataInserter": 
         DataInserter.WcfDataInserterClient dataInserterClient = new DataInserter.WcfDataInserterClient("BasicHttpBinding_IWcfDataInserter1"); 

         dataRow["URI"] = dataInserterClient.Endpoint.Address.ToString(); 
         dataRow["ServiceUptime"] = dataInserterClient.ServiceUptime(); 
         dataRow["Version"] = dataInserterClient.Version(); 

         dataInserterClient.Close(); 
         break; 

감사!

답변

1

어떻게 이런 일에 대해 :

void Foo() 
{ 
    GenericClient client = CreateClient(service); 
    //do stuff with generic client 
} 

GenericClient CreateClient(string service) 
{ 
    switch(service) 
    { 
    case "DVSSync": 
     return new WcfDVSSyncClient() 
    //etc 
    } 
}