public object CreateChannel(Type channelType, EndpointAddress address, Uri via) { if (via == null) { via = this.ClientRuntime.Via; if (via == null) { via = address.Uri; } } ServiceChannel serviceChannel = this.CreateServiceChannel(address, via); serviceChannel.Proxy = CreateProxy(channelType, channelType, MessageDirection.Input, serviceChannel); serviceChannel.ClientRuntime.GetRuntime().InitializeChannel((IClientChannel)serviceChannel.Proxy); OperationContext current = OperationContext.Current; if ((current != null) && (current.InstanceContext != null)) { current.InstanceContext.WmiChannels.Add((IChannel)serviceChannel.Proxy); serviceChannel.WmiInstanceContext = current.InstanceContext; } return(serviceChannel.Proxy); }
public TChannel CreateChannel <TChannel>(EndpointAddress address, Uri via) { if (via == null) { via = this.ClientRuntime.Via; if (via == null) { via = address.Uri; } } ServiceChannel serviceChannel = this.CreateServiceChannel(address, via); serviceChannel.Proxy = CreateProxy <TChannel>(MessageDirection.Input, serviceChannel); IClientChannel clientChannel = serviceChannel.Proxy as IClientChannel; if (clientChannel == null) { clientChannel = serviceChannel; } serviceChannel.ClientRuntime.GetRuntime().InitializeChannel(clientChannel); OperationContext current = OperationContext.Current; if ((current != null) && (current.InstanceContext != null)) { current.InstanceContext.WmiChannels.Add((IChannel)serviceChannel.Proxy); } return((TChannel)serviceChannel.Proxy); }
public static Task CreateTask(ServiceChannel channel, IMethodCallMessage methodCall, ProxyOperationRuntime operation) { if (operation.TaskTResult == ServiceReflector.VoidType) { return(TaskCreator.CreateTask(channel, operation, methodCall.InArgs)); } return(TaskCreator.CreateGenericTask(channel, operation, methodCall.InArgs)); }
internal static object CreateProxy <TChannel>(MessageDirection direction, ServiceChannel serviceChannel) { if (!typeof(TChannel).IsInterface()) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SRServiceModel.SFxChannelFactoryTypeMustBeInterface)); } return(ServiceChannelProxy.CreateProxy <TChannel>(direction, serviceChannel)); }
internal ServiceChannelProxy(System.Type interfaceType, System.Type proxiedType, MessageDirection direction, ServiceChannel serviceChannel) : base(proxiedType) { if (!MessageDirectionHelper.IsDefined(direction)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("direction")); } this.interfaceType = interfaceType; this.proxiedType = proxiedType; this.serviceChannel = serviceChannel; this.proxyRuntime = serviceChannel.ClientRuntime.GetRuntime(); this.methodDataCache = new MethodDataCache(); this.objectWrapper = new MbrObject(this, proxiedType); }
public virtual ServiceChannel CreateServiceChannel(EndpointAddress address, Uri via) { IChannelBinder binder = this.CreateInnerChannelBinder(address, via); ServiceChannel channel = new ServiceChannel(this, binder); if (binder is DuplexChannelBinder) { DuplexChannelBinder binder2 = binder as DuplexChannelBinder; binder2.ChannelHandler = new ChannelHandler(this.messageVersion, binder, channel); binder2.DefaultCloseTimeout = this.DefaultCloseTimeout; binder2.DefaultSendTimeout = this.DefaultSendTimeout; binder2.IdentityVerifier = this.clientRuntime.IdentityVerifier; } return(channel); }
public virtual ServiceChannel CreateServiceChannel(EndpointAddress address, Uri via) { IChannelBinder binder = CreateInnerChannelBinder(address, via); ServiceChannel serviceChannel = new ServiceChannel(this, binder); if (binder is DuplexChannelBinder) { DuplexChannelBinder duplexChannelBinder = binder as DuplexChannelBinder; duplexChannelBinder.ChannelHandler = new ChannelHandler(MessageVersion, binder, serviceChannel); duplexChannelBinder.DefaultCloseTimeout = DefaultCloseTimeout; duplexChannelBinder.DefaultSendTimeout = DefaultSendTimeout; duplexChannelBinder.IdentityVerifier = _clientRuntime.IdentityVerifier; } return(serviceChannel); }
// ServiceChannelProxy serves 2 roles. It is the TChannel proxy called by the client, // and it is also the handler of those calls that dispatches them to the appropriate service channel. // In .Net Remoting terms, it is conceptually the same as a RealProxy and a TransparentProxy combined. internal static TChannel CreateProxy <TChannel>(MessageDirection direction, ServiceChannel serviceChannel) { TChannel proxy = DispatchProxy.Create <TChannel, ServiceChannelProxy>(); if (proxy == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.FailedToCreateTypedProxy, typeof(TChannel)))); } ServiceChannelProxy channelProxy = (ServiceChannelProxy)(object)proxy; channelProxy._proxiedType = typeof(TChannel); channelProxy._serviceChannel = serviceChannel; channelProxy._proxyRuntime = serviceChannel.ClientRuntime.GetRuntime(); channelProxy._methodDataCache = new MethodDataCache(); return(proxy); }
public static Task <T> CreateGenericTask <T>(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters) { Func <IAsyncResult, T> endCallDelegate = (asyncResult) => { OperationContext originalOperationContext = OperationContext.Current; OperationContext.Current = asyncResult.AsyncState as OperationContext; try { return((T)channel.EndCall(operation.Action, ProxyOperationRuntime.EmptyArray, asyncResult)); } finally { OperationContext.Current = originalOperationContext; } }; return(Task <T> .Factory.FromAsync <ServiceChannel, ProxyOperationRuntime, object[]>(beginCallDelegate, endCallDelegate, channel, operation, inputParameters, OperationContext.Current)); }
static Task CreateTask(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters) { Action <IAsyncResult> endCallDelegate = (asyncResult) => { Fx.Assert(asyncResult != null, "'asyncResult' MUST NOT be NULL."); OperationContext originalOperationContext = OperationContext.Current; OperationContext.Current = asyncResult.AsyncState as OperationContext; try { channel.EndCall(operation.Action, ProxyOperationRuntime.EmptyArray, asyncResult); } finally { OperationContext.Current = originalOperationContext; } }; return(Task.Factory.FromAsync(beginCallDelegate, endCallDelegate, channel, operation, inputParameters, OperationContext.Current)); }
private static Task CreateTask(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters) { TaskCompletionSource <object> tcs = new TaskCompletionSource <object>(); bool completedCallback = false; Action <IAsyncResult> endCallDelegate = (asyncResult) => { Contract.Assert(asyncResult != null, "'asyncResult' MUST NOT be NULL."); completedCallback = true; OperationContext originalOperationContext = OperationContext.Current; OperationContext.Current = asyncResult.AsyncState as OperationContext; try { channel.EndCall(operation.Action, Array.Empty <object>(), asyncResult); tcs.TrySetResult(null); } catch (Exception e) { tcs.TrySetException(e); } finally { OperationContext.Current = originalOperationContext; } }; try { IAsyncResult ar = ServiceChannel.BeginCall(channel, operation, inputParameters, new AsyncCallback(endCallDelegate), OperationContext.Current); if (ar.CompletedSynchronously && !completedCallback) { endCallDelegate(ar); } } catch (Exception e) { tcs.TrySetException(e); } return(tcs.Task); }
internal static object CreateProxy(Type interfaceType, Type proxiedType, MessageDirection direction, ServiceChannel serviceChannel) { if (!proxiedType.IsInterface) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString("SFxChannelFactoryTypeMustBeInterface"))); } ServiceChannelProxy proxy = new ServiceChannelProxy(interfaceType, proxiedType, direction, serviceChannel); return(proxy.GetTransparentProxy()); }
internal static object CreateProxy(Type interfaceType, Type proxiedType, MessageDirection direction, ServiceChannel serviceChannel) { throw ExceptionHelper.PlatformNotSupported(); }
static Task CreateGenericTask(ServiceChannel channel, ProxyOperationRuntime operation, object[] inputParameters) { Func <ServiceChannel, ProxyOperationRuntime, object[], Task> createTaskDelegate = GetOrCreateTaskDelegate(operation.TaskTResult); return(createTaskDelegate(channel, operation, inputParameters)); }