How to get an InstanceContext from a runtime proxy constructed from metadata of another service

Posted by Don on Stack Overflow See other posts from Stack Overflow or by Don
Published on 2010-03-26T15:33:33Z Indexed on 2010/05/18 16:20 UTC
Read the original article Hit count: 720

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about wcf

Related posts about c#