예제 #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);
        }
예제 #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));
        }
예제 #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);
        }