How to get an InstanceContext from a runtime proxy constructed from metadata of another service
- by Don
I have the following function trying to create a callback InstanceContext from metadata of other services.
private InstanceContext GetCallbackIC(Type proxy, ServiceEndpoint endpoint){
try {
IDuplexContextChannel dcc;
PropertyInfo pi = proxy.GetProperty("InnerDuplexChannel");
if (pi.GetIndexParameters().Length > 0) {
dcc = (IDuplexContextChannel)pi.GetValue(Activator.CreateInstance(proxy, OperationContext.Current.InstanceContext, endpoint.Binding, endpoint.Address), new object[] { 0 });
} else {
dcc = (IDuplexContextChannel)pi.GetValue(Activator.CreateInstance(proxy, OperationContext.Current.InstanceContext, endpoint.Binding, endpoint.Address), null);
}
return new InstanceContext(dcc.CallbackInstance);
} catch (Exception ex) {
return null;
}
}
"OperationContext.Current.InstanceContext" is not the right one here because it throws me an exception - "The InstanceContext provided to the ChannelFactory contains a UserObject that does not implement the CallbackContractType ..."
How to get the InstanceContext of the proxy?
Thanks