/// <summary> /// Create WCF service proxy client /// </summary> /// <typeparam name="TServiceInterface">service contract interface</typeparam> /// <typeparam name="TBaseClass">channel base class that inherits from ClientBase</typeparam> /// <param name="beforeOperationCallback">delegate that will be executed before each operation</param> /// <param name="afterOperationCallback">delegate that will be executed after each operation</param> /// <param name="constructorParams">constructor parameters for TBaseClass</param> /// <returns>wcf proxy client with channel class inherited from <see cref="TBaseClass">TBaseClass</see></returns> public static TServiceInterface CreateInstance <TServiceInterface, TBaseClass>( Action <OperationContext> beforeOperationCallback, Action <OperationContext> afterOperationCallback, params object[] constructorParams) where TBaseClass : ClientBase <TServiceInterface> where TServiceInterface : class { if (!typeof(TServiceInterface).Attributes(typeof(ServiceContractAttribute)).Any()) { throw new ArgumentException("Provided service interface must have 'ServiceContract' attribute. Cannot create service proxy."); } var clientChannelType = WcfClientBaseTypeFactory <TServiceInterface, TBaseClass> .GenerateType(); var proxyClientType = WcfClientProxyTypeFactory <TServiceInterface, TBaseClass> .Create() .WithConstructorParameters(constructorParams) .GenerateType(); var clientInstance = (TServiceInterface)Activator.CreateInstance(proxyClientType, constructorParams); var initCallbacksMethod = proxyClientType.Method(WcfClientProxyTypeFactory <TServiceInterface, TBaseClass> .INIT_CALLBACKS_METHOD_NAME); if (initCallbacksMethod != null) { initCallbacksMethod.Invoke(clientInstance, new[] { beforeOperationCallback, afterOperationCallback }); } return(clientInstance); }
/// <summary> /// generate factory with default settings /// </summary> internal static WcfClientProxyTypeFactory <TServiceInterface, TBaseClass> Create() { var newFactory = new WcfClientProxyTypeFactory <TServiceInterface, TBaseClass>(); return(newFactory); }