tags:

views:

232

answers:

1

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

A: 

I solved the problem by creating an implement object for the callback interface at run time after retrieved the metadata. InstanceContext is only a wrapper. My original thought is not right.

Don