示例#1
0
        public IRequestClient <T> CreateRequestClient <T>(Uri destinationAddress, RequestTimeout timeout)
            where T : class
        {
            IRequestSendEndpoint <T> requestSendEndpoint = _context.GetRequestEndpoint <T>(destinationAddress);

            return(new RequestClient <T>(_context, requestSendEndpoint, timeout.Or(_context.DefaultTimeout)));
        }
示例#2
0
        public IRequestSendEndpoint <T> GetRequestEndpoint <T>(Uri destinationAddress, ConsumeContext consumeContext = default)
            where T : class
        {
            IRequestSendEndpoint <T> endpoint = _clientFactory.Context.GetRequestEndpoint <T>(destinationAddress, consumeContext);

            return(new ScopedRequestSendEndpoint <TScope, T>(endpoint, _scope));
        }
示例#3
0
        public ClientRequestHandle(ClientFactoryContext context, IRequestSendEndpoint requestSendEndpoint, TRequest message,
                                   CancellationToken cancellationToken = default, RequestTimeout timeout = default, Guid?requestId = default, TaskScheduler taskScheduler = default)
        {
            _context             = context;
            _message             = message;
            _requestSendEndpoint = requestSendEndpoint;
            _cancellationToken   = cancellationToken;

            var requestTimeout = timeout.HasValue ? timeout : _context.DefaultTimeout.HasValue ? _context.DefaultTimeout.Value : RequestTimeout.Default;

            _timeToLive = requestTimeout;

            _requestId = requestId ?? NewId.NextGuid();

            _taskScheduler = taskScheduler ??
                             (SynchronizationContext.Current == null
                    ? TaskScheduler.Default
                    : TaskScheduler.FromCurrentSynchronizationContext());

            _pipeConfigurator = new PipeConfigurator <SendContext <TRequest> >();
            _sendContext      = new TaskCompletionSource <SendContext <TRequest> >();
            _readyToSend      = new TaskCompletionSource <bool>();
            _responseHandlers = new Dictionary <Type, HandlerConnectHandle>();

            _timeoutTimer = new Timer(TimeoutExpired, this, (long)requestTimeout.Value.TotalMilliseconds, -1L);

            if (cancellationToken != default && cancellationToken.CanBeCanceled)
            {
                _registration = cancellationToken.Register(Cancel);
            }

            _send = SendRequest();

            HandleFault();
        }
示例#4
0
        public IRequestClient <T> CreateRequestClient <T>(ConsumeContext consumeContext, RequestTimeout timeout)
            where T : class
        {
            IRequestSendEndpoint <T> requestSendEndpoint = _serviceClient.CreateRequestSendEndpoint <T>(consumeContext);

            return(new RequestClient <T>(_context, requestSendEndpoint, timeout.Or(_context.DefaultTimeout)));
        }
        public async Task <TMessage> Send(Guid requestId, object values, IPipe <SendContext <TMessage> > pipe, CancellationToken cancellationToken)
        {
            IServiceClientMessageCache <TMessage> messageClient = _messageClient.IsCompletedSuccessfully()
                ? _messageClient.Result
                : await _messageClient.OrCanceled(cancellationToken).ConfigureAwait(false);

            IRequestSendEndpoint <TMessage> sendEndpoint = await messageClient
                                                           .GetServiceSendEndpoint(_clientFactoryContext, default, _consumeContext, cancellationToken)
示例#6
0
 public RequestClient(ClientFactoryContext context, IRequestSendEndpoint <TRequest> requestSendEndpoint, RequestTimeout timeout)
 {
     _context             = context;
     _requestSendEndpoint = requestSendEndpoint;
     _timeout             = timeout;
 }
 public ScopedRequestSendEndpoint(IRequestSendEndpoint <TRequest> endpoint, TScope scope)
 {
     _endpoint = endpoint;
     _scope    = scope;
 }