我必須致電ChannelFactory<TChannel>
班。但下面的代碼適用於ChannelFactory
類。我沒有任何想法,如何撥打ChannelFactory<TChannel>
。請建議我怎麼稱呼ChannelFactory<TChannel>
班。如何動態調用ChannelFactory <TChannel>?
string interfaceName = "Test";
Type myInterfaceType = Type.GetType(interfaceName);
var factoryType = typeof(ChannelFactory<>).MakeGenericType(myInterfaceType);
var factoryCtr = factoryType.GetConstructor(new[] { typeof(BasicHttpBinding), typeof(EndpointAddress) });
ChannelFactory factorry = factoryCtr.Invoke(new object[] { new BasicHttpBinding(), new EndpointAddress(cmbpath.SelectedItem.ToString()) }) as ChannelFactory;