Ejemplo n.º 1
0
        public static TServiceInterface CreateService <TServiceInterface>(Uri serviceUri) where TServiceInterface : IService
        {
            CustomContextDataDto dto     = CustomServiceContext.GetContext();
            ServiceProxyFactory  factory = new ServiceProxyFactory(CreateServiceRemotingClientFactory);
            ServicePartitionKey  key     = new ServicePartitionKey(GetLongHashCode(dto == null ? string.Empty : dto.ID));
            var serviceProxy             = factory.CreateServiceProxy <TServiceInterface>(serviceUri, key);

            return(serviceProxy);
        }
Ejemplo n.º 2
0
        public override Task <byte[]> RequestResponseAsync(IServiceRemotingRequestContext requestContext, ServiceRemotingMessageHeaders messageHeaders, byte[] requestBody)
        {
            var contextDto = messageHeaders.GetContextDto();

            CustomServiceContext.SetContext(contextDto);
            return(ServiceRequestContext.RunInRequestContext(async() =>
                                                             await base.RequestResponseAsync(
                                                                 requestContext,
                                                                 messageHeaders,
                                                                 requestBody),
                                                             contextDto));
        }
Ejemplo n.º 3
0
        public static void InvokeService <TServiceInterface>(Uri serviceUri, Action <TServiceInterface> action, CustomContextDataDto context = null) where TServiceInterface : IService
        {
            if (CustomServiceContext.GetContext() == null && context != null)
            {
                CustomServiceContext.SetContext(context);
            }
            CustomContextDataDto dto     = CustomServiceContext.GetContext();
            ServiceProxyFactory  factory = new ServiceProxyFactory(CreateServiceRemotingClientFactory);
            ServicePartitionKey  key     = new ServicePartitionKey(GetLongHashCode(dto == null ? string.Empty : dto.ID));

            ServiceRequestContext.RunInRequestContext(() => {
                var serviceProxy = factory.CreateServiceProxy <TServiceInterface>(serviceUri, key);
                return(Task.Run(() => { action(serviceProxy); }));
            }, dto);
        }