Created
February 27, 2017 13:18
-
-
Save rahulsahay19/791980d94953132d4fd1278fb718e2ea to your computer and use it in GitHub Desktop.
CreateGenericFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static object CreateGenericFactory(Type t) | |
{ | |
Type factoryType = typeof(ChannelFactory<>); | |
factoryType = factoryType.MakeGenericType(t); | |
//Call the Binding section to get the associtaed binding | |
var section = GetBindingsSection(); | |
Binding binding = null; | |
string bindingName = null; | |
List<string> contractCollection; | |
object address; | |
ClientSection clientSection; | |
var addressCollection = ApplyAddressCollection(out contractCollection, out address, out clientSection); | |
//Loop through the address collection and check for required contract | |
for (int k = 0; k < addressCollection.Count; k++) | |
{ | |
//Check for contract, if found, then pull corresponding address | |
if (contractCollection[k].Contains(t.FullName)) | |
{ | |
address = addressCollection[k].AbsoluteUri; | |
bindingName = clientSection.Endpoints[k].Binding; | |
//Now loop through collected binding name and check for configured bindings | |
binding = ApplyBindingConfiguration(section, bindingName, binding); | |
} | |
} | |
var factory = Activator.CreateInstance(factoryType, binding, address); | |
ApplyEndPointBehaviors(factory); | |
MethodInfo method = factoryType.GetMethod("CreateChannel", new Type[] { }); | |
return method.Invoke(factory, null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment