I have List<Type>
, here Type is interface which i got using reflection.
So how to create the wcf proxy using channnel factory on these Type.
like:
foreach(Type t in types)
{
t proxy = ChannelFactory<t>.CreateChannel(new NetTcpBinding(),
new EndpointAddress(serviceAddress));
}
Here t开发者_如何学Python is interface but the above code is giving compiler error.Can anybody tell me how to create wcf service proxy on Type.
You can use reflection and call the method Type.MakeGenericType
:
foreach (Type t in types)
{
Type genType = typeof(ChannelFactory<>).MakeGenericType(t);
MethodInfo createChannelMethod = genType.GetMethod("CreateChannel",
new[] { typeof(Binding),
typeof(EndpointAddress) });
var proxy = createChannelMethod.Invoke(
null,
BindingFlags.Static,
null,
new object[] {
new NetTcpBinding(),
new EndpointAddress(serviceAddress)
},
null);
}
精彩评论