Esempio n. 1
0
        /// <summary>
        ///     Constructs a WCF based service remoting client factory.
        /// </summary>
        /// <param name="clientBinding">
        ///     WCF binding to use for the client. If the client binding is not specified or null,
        ///     a default client binding is created using
        ///     <see cref="Microsoft.ServiceFabric.Services.Communication.Wcf.WcfUtility.CreateTcpClientBinding"/> method
        ///     which creates a <see cref="System.ServiceModel.NetTcpBinding"/> with no security.
        /// </param>
        /// <param name="callbackClient">
        ///     The callback client that receives the callbacks from the service.
        /// </param>
        /// <param name="exceptionHandlers">
        ///     Exception handlers to handle the exceptions encountered in communicating with the service.
        /// </param>
        /// <param name="servicePartitionResolver">
        ///     Service partition resolver to resolve the service endpoints. If not specified, a default
        ///     service partition resolver returned by <see cref="ServicePartitionResolver.GetDefault"/> is used.
        /// </param>
        /// <param name="traceId">
        ///     Id to use in diagnostics traces from this component.
        /// </param>
        /// <param name="createWcfClientFactory">
        ///     Delegate function that creates <see cref="Microsoft.ServiceFabric.Services.Communication.Wcf.Client.WcfCommunicationClientFactory{TServiceContract}"/> using the
        ///     <see cref="Microsoft.ServiceFabric.Services.Remoting.V2.Wcf.IServiceRemotingContract"/>.
        /// </param>
        /// <param name="serializationProvider"></param>
        /// <remarks>
        ///     This factory uses <see cref="WcfExceptionHandler"/> and <see cref="ServiceRemotingExceptionHandler"/> in addition to the
        ///     exception handlers supplied to the constructor.
        /// </remarks>
        public WcfServiceRemotingClientFactory(
            Binding clientBinding = null,
            IServiceRemotingCallbackMessageHandler callbackClient = null,
            IEnumerable <IExceptionHandler> exceptionHandlers     = null,
            IServicePartitionResolver servicePartitionResolver    = null,
            string traceId = null,
            Func <
                Binding,
                IEnumerable <IExceptionHandler>,
                IServicePartitionResolver,
                string,
                IServiceRemotingCallbackContract,
                WcfCommunicationClientFactory <IServiceRemotingContract> > createWcfClientFactory = null,
            IServiceRemotingMessageSerializationProvider serializationProvider = null)

        {
            if (serializationProvider == null)
            {
                serializationProvider = new BasicDataContractSerializationProvider();
            }

            var serializersManager = new ServiceRemotingMessageSerializersManager(serializationProvider,
                                                                                  new BasicDataContractHeaderSerializer());

            this.Initialize(serializersManager,
                            clientBinding,
                            callbackClient,
                            exceptionHandlers,
                            servicePartitionResolver,
                            traceId,
                            createWcfClientFactory);
        }
        private void Initialize(FabricTransportRemotingSettings remotingSettings,
                                IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler,
                                IServicePartitionResolver servicePartitionResolver,
                                IEnumerable <IExceptionHandler> exceptionHandlers,
                                string traceId,
                                IServiceRemotingMessageSerializationProvider serializationProvider,
                                IServiceRemotingMessageHeaderSerializer headerSerializer = null)
        {
            remotingSettings = remotingSettings ?? FabricTransportRemotingSettings.GetDefault();

            if (headerSerializer == null)
            {
                headerSerializer = new ServiceRemotingMessageHeaderSerializer(new BufferPoolManager(remotingSettings.HeaderBufferSize, remotingSettings.HeaderMaxBufferCount));
            }

            var serializersManager = new ServiceRemotingMessageSerializersManager(serializationProvider,
                                                                                  headerSerializer);


            this.Initialize(remotingSettings,
                            remotingCallbackMessageHandler,
                            servicePartitionResolver,
                            exceptionHandlers,
                            traceId,
                            serializersManager.GetSerializationProvider().CreateMessageBodyFactory(),
                            serializersManager);
        }
Esempio n. 3
0
        private void Initialize(ServiceRemotingMessageSerializersManager serializersManager, Binding clientBinding,
                                IServiceRemotingCallbackMessageHandler callbackClient, IEnumerable <IExceptionHandler> exceptionHandlers,
                                IServicePartitionResolver servicePartitionResolver, string traceId, Func <Binding, IEnumerable <IExceptionHandler>, IServicePartitionResolver, string, IServiceRemotingCallbackContract, WcfCommunicationClientFactory <IServiceRemotingContract> > createWcfClientFactory)
        {
            this.serializersManager = serializersManager;
            if (traceId == null)
            {
                traceId = Guid.NewGuid().ToString();
            }

            if (createWcfClientFactory == null)
            {
                this.wcfFactory = new WcfCommunicationClientFactory <IServiceRemotingContract>(
                    clientBinding,
                    GetExceptionHandlers(exceptionHandlers, traceId),
                    servicePartitionResolver,
                    traceId,
                    this.GetCallbackImplementation(callbackClient));
            }
            else
            {
                this.wcfFactory = createWcfClientFactory(
                    clientBinding,
                    GetExceptionHandlers(exceptionHandlers, traceId),
                    servicePartitionResolver,
                    traceId,
                    this.GetCallbackImplementation(callbackClient));
            }


            this.wcfFactory.ClientConnected    += this.OnClientConnected;
            this.wcfFactory.ClientDisconnected += this.OnClientDisconnected;

            this.remotingMessageBodyFactory = this.serializersManager.GetSerializationProvider().CreateMessageBodyFactory();
        }
        internal CorrelatingFabricTransportServiceRemotingClientFactory(
            FabricTransportRemotingSettings remotingSettings = null,
            IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler = null,
            IServicePartitionResolver servicePartitionResolver = null,
            IEnumerable <IExceptionHandler> exceptionHandlers  = null,
            string traceId = null,
            IServiceRemotingMessageSerializationProvider serializationProvider = null,
            IServiceRemotingClientFactory inner = null,
            Action <CallSummary> raiseSummary   = null,
            string remoteServiceName            = null)
        {
            if (inner == null)
            {
                inner = new FabricTransportServiceRemotingClientFactory(
                    remotingSettings,
                    remotingCallbackMessageHandler,
                    servicePartitionResolver,
                    exceptionHandlers,
                    traceId,
                    serializationProvider);
            }

            _inner             = inner;
            _raiseSummary      = raiseSummary;
            _remoteServiceName = remoteServiceName ?? "unknown";
        }
 public CustomActorRemotingClientFactory(IServiceRemotingCallbackMessageHandler handler)
 {
     this.innerFactory = new FabricTransportActorRemotingClientFactory(
         new FabricTransportRemotingSettings(),
         handler);
     this.innerFactory.ClientConnected    += this.ClientConnected;
     this.innerFactory.ClientDisconnected += this.ClientDisconnected;
 }
Esempio n. 6
0
 public CorrelatingFabricTransportServiceRemotingClientFactory(
     FabricTransportRemotingSettings remotingSettings = null,
     IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler = null,
     IServicePartitionResolver servicePartitionResolver = null,
     IEnumerable <IExceptionHandler> exceptionHandlers  = null,
     string traceId = null,
     IServiceRemotingMessageSerializationProvider serializationProvider = null) :
     this(remotingSettings, remotingCallbackMessageHandler, servicePartitionResolver, exceptionHandlers, traceId, serializationProvider, null)
 {
 }
 /// <summary>
 ///     Creates a V2 service remoting client factory to connect to the remoted actor interfaces.
 /// </summary>
 /// <param name="callbackMessageHandler">
 ///     Client implementation where the callbacks should be dispatched.
 /// </param>
 /// <returns>
 ///     A <see cref="Microsoft.ServiceFabric.Actors.Remoting.V2.Wcf.Client.WcfActorRemotingClientFactory"/>
 ///     as <see cref="Microsoft.ServiceFabric.Services.Remoting.V2.Client.IServiceRemotingClientFactory"/>
 ///     that can be used with <see cref="ActorProxyFactory"/> to
 ///     generate actor proxy to talk to the actor over remoted actor interface.
 /// </returns>
 public override IServiceRemotingClientFactory CreateServiceRemotingClientFactoryV2(
     IServiceRemotingCallbackMessageHandler callbackMessageHandler)
 {
     return(new Microsoft.ServiceFabric.Actors.Remoting.V2.Wcf.Client.WcfActorRemotingClientFactory(
                WcfUtility.CreateTcpClientBinding(
                    maxMessageSize: this.GetMaxMessageSize(),
                    openTimeout: this.GetOpenTimeout(),
                    closeTimeout: this.GetCloseTimeout()),
                callbackMessageHandler));
 }
Esempio n. 8
0
        /// <summary>
        /// Creates service remoting client factory.
        /// </summary>
        /// <param name="callbackClient">Callback from the remoting listener to the client.</param>
        /// <returns>Created service remoting client factory as <see cref="IServiceRemotingClientFactory"/></returns>
        protected virtual IServiceRemotingClientFactory CreateServiceRemotingClientFactory(
            IServiceRemotingCallbackMessageHandler callbackClient)
        {
            if (this.createServiceRemotingClientFactory != null)
            {
                return(this.createServiceRemotingClientFactory(callbackClient));
            }

            return(null);
        }
Esempio n. 9
0
 /// <summary>
 ///     Creates a service remoting client factory that can be used by the
 ///     <see cref="Microsoft.ServiceFabric.Services.Remoting.Client.ServiceProxyFactory"/>
 ///     to create a proxy for the remoted interface of the service.
 /// </summary>
 /// <param name="callbackMessageHandler">
 ///     Client implementation where the callbacks should be dispatched.
 /// </param>
 /// <returns>
 ///     A <see cref="Microsoft.ServiceFabric.Services.Remoting.V2.Wcf.Client.WcfServiceRemotingClientFactory"/>.
 /// </returns>
 public override V2.Client.IServiceRemotingClientFactory CreateServiceRemotingClientFactoryV2(
     IServiceRemotingCallbackMessageHandler callbackMessageHandler)
 {
     return(new Services.Remoting.V2.Wcf.Client.WcfServiceRemotingClientFactory(
                WcfUtility.CreateTcpClientBinding(
                    this.GetMaxMessageSize(),
                    this.GetOpenTimeout(),
                    this.GetCloseTimeout()),
                callbackMessageHandler));
 }
Esempio n. 10
0
        /// <summary>
        ///     Creates a  V2 service remoting client factory for connecting to the service over remoted service interfaces.
        /// </summary>
        /// <param name="callbackMessageHandler">
        ///    The client implementation where the callbacks should be dispatched.
        /// </param>
        /// <returns>
        ///     A <see cref="FabricTransportServiceRemotingClientFactory"/>
        ///     as <see cref="V2.Client.IServiceRemotingClientFactory"/>
        ///     that can be used with <see cref="Remoting.Client.ServiceProxyFactory"/> to
        ///     generate service proxy to talk to a stateless or stateful service over remoted actor interface.
        /// </returns>

        public override V2.Client.IServiceRemotingClientFactory CreateServiceRemotingClientFactoryV2(
            IServiceRemotingCallbackMessageHandler callbackMessageHandler)
        {
            var settings = FabricTransportRemotingSettings.GetDefault();

            settings.MaxMessageSize   = this.GetAndValidateMaxMessageSize(settings.MaxMessageSize);
            settings.OperationTimeout = this.GetAndValidateOperationTimeout(settings.OperationTimeout);
            settings.KeepAliveTimeout = this.GetKeepAliveTimeout(settings.KeepAliveTimeout);
            settings.ConnectTimeout   = this.GetConnectTimeout(settings.ConnectTimeout);
            return(new V2.FabricTransport.Client.FabricTransportServiceRemotingClientFactory(remotingSettings: settings,
                                                                                             remotingCallbackMessageHandler: callbackMessageHandler));
        }
Esempio n. 11
0
 private IServiceRemotingCallbackContract GetCallbackImplementation(
     IServiceRemotingCallbackMessageHandler callbackClient)
 {
     if (callbackClient == null)
     {
         return(new NoOpCallbackReceiver());
     }
     else
     {
         return(new CallbackReceiver(callbackClient,
                                     this.serializersManager));
     }
 }
Esempio n. 12
0
        /// <summary>
        /// Constructs a fabric transport based actor remoting client factory.
        /// </summary>
        /// <param name="fabricTransportRemotingSettings">
        ///     The settings for the fabric transport. If the settings are not provided or null, default settings
        ///     with no security.
        /// </param>
        /// <param name="callbackMessageHandler">
        ///     The callback client that receives the callbacks from the service.
        /// </param>
        /// <param name="servicePartitionResolver">
        ///     Service partition resolver to resolve the service endpoints. If not specified, a default
        ///     service partition resolver returned by <see cref="ServicePartitionResolver.GetDefault"/> is used.
        /// </param>
        /// <param name="exceptionHandlers">
        ///     Exception handlers to handle the exceptions encountered in communicating with the actor.
        /// </param>
        /// <param name="traceId">
        ///     Id to use in diagnostics traces from this component.
        /// </param>
        /// <param name="serializationProvider"></param>
        public FabricTransportActorRemotingClientFactory(
            FabricTransportRemotingSettings fabricTransportRemotingSettings,
            IServiceRemotingCallbackMessageHandler callbackMessageHandler,
            IServicePartitionResolver servicePartitionResolver = null,
            IEnumerable <IExceptionHandler> exceptionHandlers  = null,
            string traceId = null,
            IServiceRemotingMessageSerializationProvider serializationProvider = null) :
            base(IntializeSerializationManager(serializationProvider, fabricTransportRemotingSettings),
                 fabricTransportRemotingSettings,
                 callbackMessageHandler,
                 servicePartitionResolver,
                 GetExceptionHandlers(exceptionHandlers),
                 traceId)

        {
        }
 internal FabricTransportServiceRemotingClientFactory(
     ServiceRemotingMessageSerializersManager serializersManager,
     FabricTransportRemotingSettings remotingSettings = null,
     IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler = null,
     IServicePartitionResolver servicePartitionResolver = null,
     IEnumerable <IExceptionHandler> exceptionHandlers  = null,
     string traceId = null)
 {
     this.Initialize(remotingSettings,
                     remotingCallbackMessageHandler,
                     servicePartitionResolver,
                     exceptionHandlers,
                     traceId,
                     serializersManager.GetSerializationProvider().CreateMessageBodyFactory(),
                     serializersManager);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="remotingSettings"></param>
 /// <param name="remotingCallbackMessageHandler"></param>
 /// <param name="servicePartitionResolver"></param>
 /// <param name="exceptionHandlers"></param>
 /// <param name="traceId"></param>
 /// <param name="serializersManager"></param>
 public FabricTransportServiceRemotingClientFactoryImpl(
     ServiceRemotingMessageSerializersManager serializersManager,
     FabricTransportRemotingSettings remotingSettings,
     IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler = null,
     IServicePartitionResolver servicePartitionResolver = null,
     IEnumerable <IExceptionHandler> exceptionHandlers  = null,
     string traceId = null)
     : base(
         servicePartitionResolver,
         GetExceptionHandlers(exceptionHandlers),
         traceId)
 {
     this.settings           = remotingSettings ?? FabricTransportRemotingSettings.GetDefault();
     this.serializersManager = serializersManager;
     this.disposer           = new NativeFabricTransportMessageDisposer();
     this.fabricTransportRemotingCallbackMessageHandler = new FabricTransportRemotingCallbackMessageHandler(remotingCallbackMessageHandler, this.serializersManager);
 }
Esempio n. 15
0
 /// <summary>
 ///     Constructs a WCF based actor remoting factory.
 /// </summary>
 /// <param name="clientBinding">
 ///     WCF binding to use for the client. If the client binding is null,
 ///     a default client binding is created using
 ///     <see cref="Microsoft.ServiceFabric.Services.Communication.Wcf.WcfUtility.CreateTcpClientBinding"/> method
 ///     which creates a <see cref="System.ServiceModel.NetTcpBinding"/> with no security.
 /// </param>
 /// <param name="callbackClient">
 ///     The callback client that receives the callbacks from the service.
 /// </param>
 /// <param name="exceptionHandlers">
 ///     Exception handlers to handle the exceptions encountered in communicating with the service.
 /// </param>
 /// <param name="servicePartitionResolver">
 ///     Service partition resolver to resolve the service endpoints. If not specified, a default
 ///     service partition resolver returned by <see cref="ServicePartitionResolver.GetDefault"/> is used.
 /// </param>
 /// <param name="traceId">
 ///     Id to use in diagnostics traces from this component.
 /// </param>
 /// <param name="serializationProvider"></param>
 /// <remarks>
 ///     This factory uses <see cref="Microsoft.ServiceFabric.Services.Communication.Wcf.Client.WcfExceptionHandler"/>,
 ///     <see cref="Microsoft.ServiceFabric.Actors.Remoting.Client.ActorRemotingExceptionHandler"/>, in addition to the
 ///     exception handlers supplied to the constructor.
 /// </remarks>
 public WcfActorRemotingClientFactory(
     Binding clientBinding,
     IServiceRemotingCallbackMessageHandler callbackClient,
     IEnumerable <IExceptionHandler> exceptionHandlers  = null,
     IServicePartitionResolver servicePartitionResolver = null,
     string traceId = null,
     IServiceRemotingMessageSerializationProvider serializationProvider = null) :
     base(
         new ActorRemotingSerializationManager(serializationProvider ?? new BasicDataContractSerializationProvider(),
                                               new BasicDataContractActorHeaderSerializer()),
         clientBinding,
         callbackClient,
         GetExceptionHandlers(exceptionHandlers),
         servicePartitionResolver,
         traceId)
 {
 }
Esempio n. 16
0
 internal WcfServiceRemotingClientFactory(
     ServiceRemotingMessageSerializersManager serializersManager,
     Binding clientBinding = null,
     IServiceRemotingCallbackMessageHandler callbackClient = null,
     IEnumerable <IExceptionHandler> exceptionHandlers     = null,
     IServicePartitionResolver servicePartitionResolver    = null,
     string traceId = null,
     Func <
         Binding,
         IEnumerable <IExceptionHandler>,
         IServicePartitionResolver,
         string,
         IServiceRemotingCallbackContract,
         WcfCommunicationClientFactory <IServiceRemotingContract> > createWcfClientFactory = null
     )
 {
     this.Initialize(serializersManager, clientBinding, callbackClient, exceptionHandlers, servicePartitionResolver, traceId, createWcfClientFactory);
 }
 private void Initialize(FabricTransportRemotingSettings remotingSettings,
                         IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler,
                         IServicePartitionResolver servicePartitionResolver,
                         IEnumerable <IExceptionHandler> exceptionHandlers,
                         string traceId,
                         IServiceRemotingMessageBodyFactory messageBodyFactory,
                         ServiceRemotingMessageSerializersManager serializersManager)
 {
     this.remotingMessageBodyFactory = messageBodyFactory;
     this.clientFactoryImpl          = new FabricTransportServiceRemotingClientFactoryImpl(
         serializersManager,
         remotingSettings,
         remotingCallbackMessageHandler,
         servicePartitionResolver,
         exceptionHandlers,
         traceId
         );
     this.clientFactoryImpl.ClientConnected    += this.OnClientConnected;
     this.clientFactoryImpl.ClientDisconnected += this.OnClientDisconnected;
 }
Esempio n. 18
0
        internal CorrelatingFabricTransportServiceRemotingClientFactory(
            FabricTransportRemotingSettings remotingSettings = null,
            IServiceRemotingCallbackMessageHandler remotingCallbackMessageHandler = null,
            IServicePartitionResolver servicePartitionResolver = null,
            IEnumerable <IExceptionHandler> exceptionHandlers  = null,
            string traceId = null,
            IServiceRemotingMessageSerializationProvider serializationProvider = null,
            IServiceRemotingClientFactory inner = null)
        {
            if (inner == null)
            {
                inner = new FabricTransportServiceRemotingClientFactory(
                    remotingSettings,
                    remotingCallbackMessageHandler,
                    servicePartitionResolver,
                    exceptionHandlers,
                    traceId,
                    serializationProvider);
            }

            _inner = inner;
        }
Esempio n. 19
0
 /// <summary>
 /// Constructs a fabric transport based actor remoting client factory.
 /// </summary>
 /// <param name="callbackMessageHandler">
 ///     The callback client that receives the callbacks from the service.
 /// </param>
 public FabricTransportActorRemotingClientFactory(
     IServiceRemotingCallbackMessageHandler callbackMessageHandler)
     : this(FabricTransportRemotingSettings.GetDefault(), callbackMessageHandler)
 {
 }
Esempio n. 20
0
 public FabricTransportRemotingCallbackMessageHandler(IServiceRemotingCallbackMessageHandler remotingCallbackClient,
                                                      ServiceRemotingMessageSerializersManager manager)
 {
     this.remotingCallbackClient = remotingCallbackClient;
     this.manager = manager;
 }
Esempio n. 21
0
 public CallbackReceiver(IServiceRemotingCallbackMessageHandler callbackHandler,
                         ServiceRemotingMessageSerializersManager serializersManager)
 {
     this.callbackHandler    = callbackHandler;
     this.serializersManager = serializersManager;
 }
 public CustomServiceRemotingClientFactory(IServiceRemotingCallbackMessageHandler serviceRemotingCallbackMessageHandler)
 {
     _innerServiceRemotingClientFactory = new FabricTransportServiceRemotingClientFactory(
         RemotingSettings, remotingCallbackMessageHandler: serviceRemotingCallbackMessageHandler, serializationProvider: new ServiceRemotingJsonSerializationProvider());
 }
Esempio n. 23
0
 /// <summary>
 ///     Constructs a WCF based actor remoting factory.
 /// </summary>
 /// <param name="callbackClient">
 ///     The callback client that receives the callbacks from the service.
 /// </param>
 public WcfActorRemotingClientFactory(
     IServiceRemotingCallbackMessageHandler callbackClient)
     : this(null, callbackClient)
 {
 }
Esempio n. 24
0
 /// <summary>
 /// Create custom client using <see cref="ExtendedFabricTransportServiceRemotingClientFactory" />
 /// </summary>
 /// <param name="callbackMessageHandler"></param>
 /// <returns></returns>
 public override IServiceRemotingClientFactory CreateServiceRemotingClientFactoryV2(IServiceRemotingCallbackMessageHandler callbackMessageHandler)
 {
     // debug code to get all registered even sources from .net framework (see https://referencesource.microsoft.com/mscorlib/system/diagnostics/eventing/eventsource.cs.html#5dcdbf0a2aacfd4c)
     //var p = typeof(EventListener).GetField("s_EventSources", BindingFlags.Static | BindingFlags.NonPublic);
     //var r = p.GetValue(null);
     // send default implementation as attribute
     return(new ExtendedFabricTransportServiceRemotingClientFactory(base.CreateServiceRemotingClientFactoryV2(callbackMessageHandler)));
 }
Esempio n. 25
0
 public override IServiceRemotingClientFactory CreateServiceRemotingClientFactoryV2(IServiceRemotingCallbackMessageHandler callbackMessageHandler)
 {
     return(new FabricTransportActorRemotingClientFactory(new FabricTransportRemotingSettings(), callbackMessageHandler, (IServicePartitionResolver)null, (IEnumerable <IExceptionHandler>)null, (string)null, new ServiceRemotingDataContractSerializationProvider()));
 }