protected void PerformInvocation(IInvocation invocation, IWcfChannelHolder channelHolder, Action <WcfInvocation> action) { var wcfInvocation = new WcfInvocation(channelHolder, invocation); ApplyChannelPipeline(0, wcfInvocation, action); invocation.ReturnValue = wcfInvocation.ReturnValue; }
public void WantsToUseUnusableChannel(IWcfChannelHolder channelHolder, MethodInfo method) { if (Refresh) { channelHolder.RefreshChannel(); } }
public AsyncWcfCallContext(AsyncCallback callback, object state, AsyncType asyncType, IWcfChannelHolder channelHolder, object defaultReturn) { this.callback = callback; this.state = state; this.asyncType = asyncType; ChannelHolder = channelHolder; this.defaultReturn = defaultReturn; }
public WcfRemotingInterceptor(WcfClientExtension clients, IWcfChannelHolder channelHolder) { if (channelHolder == null) { throw new ArgumentException("The given Proxy is not valid WCF dynamic proxy."); } this.channelHolder = channelHolder; pipeline = CreateChannelPipeline(clients); }
protected virtual void PerformInvocation(IInvocation invocation, IWcfChannelHolder channelHolder) { PerformInvocation(invocation, channelHolder, wcfInvocation => { var realProxy = channelHolder.RealProxy; var message = new MethodCallMessage(wcfInvocation.Method, wcfInvocation.Arguments); var returnMessage = (IMethodReturnMessage)realProxy.Invoke(message); if (returnMessage.Exception != null) { throw returnMessage.Exception; } wcfInvocation.ReturnValue = returnMessage.ReturnValue; }); }
protected override void PerformInvocation(IInvocation invocation, IWcfChannelHolder channelHolder) { if (callContext == null) { base.PerformInvocation(invocation, channelHolder); return; } var context = callContext; callContext = null; CallBeginMethod(invocation, context, channelHolder); }
protected virtual void PerformInvocation(IInvocation invocation, IWcfChannelHolder channelHolder) { Action sendAction = () => { var proxy = channelHolder.RealProxy; var message = new MethodCallMessage(invocation.Method, invocation.Arguments); var returnMessage = (IMethodReturnMessage)proxy.Invoke(message); if (returnMessage.Exception != null) { throw returnMessage.Exception; } invocation.ReturnValue = returnMessage.ReturnValue; }; ApplyActionPolicy(channelHolder, invocation, sendAction); }
protected void ApplyRefreshPolicy(IWcfChannelHolder channelHolder, IInvocation invocation) { if (!channelHolder.IsChannelUsable) { bool hasCustomRefreshPolicy = false; var channelBurden = channelHolder.ChannelBurden; foreach (var refreshPolicy in channelBurden.Dependencies .OfType<IRefreshChannelPolicy>().OrderBy(p => p.ExecutionOrder)) { refreshPolicy.WantsToUseUnusableChannel(channelHolder, invocation.Method); hasCustomRefreshPolicy = true; } if (!hasCustomRefreshPolicy) { channelHolder.RefreshChannel(); } } }
/// <inheritdoc /> public bool Perform(IWcfChannelHolder channelHolder, MethodInfo method, Action action) { bool reconnect = false; try { action(); } catch (ChannelTerminatedException) { reconnect = true; } catch (CommunicationObjectFaultedException) { reconnect = true; } catch (CommunicationObjectAbortedException) { reconnect = true; } catch (MessageSecurityException) { reconnect = true; } catch (CommunicationException cex) { if (cex.GetType() != typeof(CommunicationException)) { throw; } reconnect = true; } if (reconnect) { channelHolder.RefreshChannel(); action(); } return true; }
private IInterceptor[] GetInterceptors(IKernel kernel, ComponentModel model, IWcfChannelHolder channelHolder, CreationContext context) { var interceptors = ObtainInterceptors(kernel, model, context); // TODO: this should be static and happen in IContributeComponentModelConstruction preferably var clientModel = (IWcfClientModel)model.ExtendedProperties[WcfConstants.ClientModelKey]; Array.Resize(ref interceptors, interceptors.Length + (clientModel.WantsAsyncCapability ? 2 : 1)); int index = interceptors.Length; interceptors[--index] = new WcfRemotingInterceptor(clients, channelHolder); if (clientModel.WantsAsyncCapability) { var getAsyncType = WcfUtils.SafeInitialize(ref asyncType, () => AsyncType.GetAsyncType(model.Service)); interceptors[--index] = new WcfRemotingAsyncInterceptor(getAsyncType, clients, channelHolder); } return(interceptors); }
private IInterceptor[] GetInterceptors(IKernel kernel, ComponentModel model, Type serviceContract, IWcfChannelHolder channelHolder, CreationContext context) { var interceptors = ObtainInterceptors(kernel, model, context); // TODO: this should be static and happen in IContributeComponentModelConstruction preferably var clientModel = (IWcfClientModel)model.ExtendedProperties[WcfConstants.ClientModelKey]; Array.Resize(ref interceptors, interceptors.Length + (clientModel.WantsAsyncCapability ? 2 : 1)); int index = interceptors.Length; interceptors[--index] = new WcfRemotingInterceptor(clients, channelHolder); if (clientModel.WantsAsyncCapability) { if (channelHolder.RealProxy == null) { throw new InvalidOperationException(string.Format( "Component {0} requested async support, but the channel does not support this capability.", model.Name)); } var getAsyncType = WcfUtils.SafeInitialize(ref asyncType, () => AsyncType.GetAsyncType(serviceContract)); interceptors[--index] = new WcfRemotingAsyncInterceptor(getAsyncType, clients, channelHolder); } return(interceptors); }
protected void ApplyActionPolicy(IWcfChannelHolder channelHolder, IInvocation invocation, Action action) { bool actionPolicyApplied = false; var channelBurden = channelHolder.ChannelBurden; foreach (var actionPolicy in channelBurden.Dependencies .OfType<IChannelActionPolicy>().OrderBy(p => p.ExecutionOrder)) { if (actionPolicy.Perform(channelHolder, invocation.Method, action)) { actionPolicyApplied = true; break; } } if (!actionPolicyApplied) { if (clients.DefaultChannelPolicy != null) { clients.DefaultChannelPolicy.Perform(channelHolder, invocation.Method, action); } else { action(); } } }
public WcfInvocation(IWcfChannelHolder channelHolder, IInvocation invocation) { this.channelHolder = channelHolder; this.invocation = invocation; }
public WcfRemotingAsyncInterceptor(AsyncType asyncType, WcfClientExtension clients, IWcfChannelHolder channelHolder) : base(clients, channelHolder) { this.asyncType = asyncType; }
public WcfInvocation(IWcfChannelHolder channelHolder, IInvocation invocation) { ChannelHolder = channelHolder; Arguments = invocation.Arguments; Method = invocation.Method; }
public WcfRemotingInterceptor(WcfClientExtension clients, IWcfChannelHolder channelHolder) { pipeline = CreateChannelPipeline(clients, channelHolder); }
private IInterceptor[] GetInterceptors(IKernel kernel, ComponentModel model,IWcfChannelHolder channelHolder, CreationContext context) { var interceptors = ObtainInterceptors(kernel, model, context); // TODO: this should be static and happen in IContributeComponentModelConstruction preferably var clientModel = (IWcfClientModel)model.ExtendedProperties[WcfConstants.ClientModelKey]; Array.Resize(ref interceptors, interceptors.Length + (clientModel.WantsAsyncCapability ? 2 : 1)); int index = interceptors.Length; interceptors[--index] = new WcfRemotingInterceptor(clients, channelHolder); if (clientModel.WantsAsyncCapability) { var getAsyncType = WcfUtils.SafeInitialize(ref asyncType, () => AsyncType.GetAsyncType(model.Service)); interceptors[--index] = new WcfRemotingAsyncInterceptor(getAsyncType, clients, channelHolder); } return interceptors; }
private void CallBeginMethod(IInvocation invocation, AsyncWcfCallContext context, IWcfChannelHolder channelHolder) { context.Init(invocation.Method, invocation.Arguments); PerformInvocation(invocation, channelHolder, wcfInvocation => { var message = context.CreateBeginMessage(); var returnMessage = context.ChannelHolder.RealProxy.Invoke(message) as IMethodReturnMessage; wcfInvocation.ReturnValue = context.PostProcess(returnMessage); }); }
private static IWcfPolicy[] CreateChannelPipeline(WcfClientExtension clients, IWcfChannelHolder channelHolder) { var policies = channelHolder.ChannelBurden.Dependencies.OfType <IWcfPolicy>() .OrderBy(policy => policy.ExecutionOrder).ToArray(); if (policies.Length == 0 && clients.DefaultChannelPolicy != null) { policies = clients.DefaultChannelPolicy.ToArray(); } return(policies); }
private static IWcfPolicy[] CreateChannelPipeline(WcfClientExtension clients, IWcfChannelHolder channelHolder) { var policies = channelHolder.ChannelBurden.Dependencies.OfType<IWcfPolicy>() .OrderBy(policy => policy.ExecutionOrder).ToArray(); if (policies.Length == 0 && clients.DefaultChannelPolicy != null) { policies = clients.DefaultChannelPolicy.ToArray(); } return policies; }
protected void PerformInvocation(IInvocation invocation, IWcfChannelHolder channelHolder, Action<WcfInvocation> action) { var wcfInvocation = new WcfInvocation(channelHolder, invocation); ApplyChannelPipeline(0, wcfInvocation, action); invocation.ReturnValue = wcfInvocation.ReturnValue; }
private IInterceptor[] GetInterceptors(IKernel kernel, ComponentModel model, Type serviceContract, IWcfChannelHolder channelHolder, CreationContext context) { var interceptors = ObtainInterceptors(kernel, model, context); // TODO: this should be static and happen in IContributeComponentModelConstruction preferably var clientModel = (IWcfClientModel)model.ExtendedProperties[WcfConstants.ClientModelKey]; Array.Resize(ref interceptors, interceptors.Length + (clientModel.WantsAsyncCapability ? 2 : 1)); int index = interceptors.Length; interceptors[--index] = new WcfRemotingInterceptor(clients, channelHolder); if (clientModel.WantsAsyncCapability) { if (channelHolder.RealProxy == null) { throw new InvalidOperationException(string.Format( "Component {0} requested async support, but the channel does not support this capability.", model.Name)); } var getAsyncType = WcfUtils.SafeInitialize(ref asyncType, () => AsyncType.GetAsyncType(serviceContract)); interceptors[--index] = new WcfRemotingAsyncInterceptor(getAsyncType, clients, channelHolder); } return interceptors; }