当前位置: 首页>>代码示例>>C#>>正文


C# Http.DelegatingHandler类代码示例

本文整理汇总了C#中System.Net.Http.DelegatingHandler的典型用法代码示例。如果您正苦于以下问题:C# DelegatingHandler类的具体用法?C# DelegatingHandler怎么用?C# DelegatingHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DelegatingHandler类属于System.Net.Http命名空间,在下文中一共展示了DelegatingHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConfigureRoute

        public MusicStoreBootStrap ConfigureRoute()
        {
            // List of delegating handlers.
            DelegatingHandler[] handlers = new DelegatingHandler[] { new AdminAuthorizationMessageHandler(new AdminUserQuery()) };

            // Create a message handler chain with an end-point.
            var routeHandlers = HttpClientFactory.CreatePipeline(
                new HttpControllerDispatcher(httpConfiguration), handlers);
            httpConfiguration.Routes.MapHttpRoute(
                name: "AdminRoutes",
                routeTemplate: "api/AdminUser/{user}",
                defaults: new { controller = "AdminUser", user = RouteParameter.Optional }
                , constraints: null
                , handler: routeHandlers);

            httpConfiguration.Routes.MapHttpRoute(
              name: "Inventory",
              routeTemplate: "api/Inventory/{id}",
              defaults: new { controller = "Inventory", id = RouteParameter.Optional }
              , constraints: null
              , handler: routeHandlers);

            httpConfiguration.Routes.MapHttpRoute(
             name: "ActionApi",
             routeTemplate: "api/{controller}/{action}/{id}",
             defaults: new { controller = "Product", id = RouteParameter.Optional });

            httpConfiguration.Routes.MapHttpRoute(
             name: "DefaultApi",
             routeTemplate: "api/{controller}/{id}",
             defaults: new { controller = "Product", id = RouteParameter.Optional });
            httpConfiguration.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

            return this;
        }
开发者ID:satish860,项目名称:MusicStoreAPI,代码行数:35,代码来源:MusicStoreBootStrap.cs

示例2: CreateHandler

 public DelegatingHandler CreateHandler(HttpConfiguration httpConfig, DelegatingHandler innerHandler = null)
 {
     return new CorsMessageHandler(this, httpConfig)
     {
         InnerHandler = innerHandler
     };
 }
开发者ID:rchern,项目名称:Thinktecture.IdentityModel.40,代码行数:7,代码来源:WebApiCorsConfiguration.cs

示例3: Register

        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            config.MessageHandlers.Add(new CustomHeaderHandler());

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
            var handlers = new DelegatingHandler[]
            {
                new PreRouteMessageHandler()
            };
            var routeHandlers = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(config), handlers);
            config.Routes.MapHttpRoute(
                name: "Route2",
                routeTemplate: "api1/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional },
                constraints: null,
                handler: routeHandlers
            );
            config.MessageHandlers.Add(new MethodOverrideHandler());
        }
开发者ID:g-srinivas,项目名称:Srini-WebApi,代码行数:28,代码来源:WebApiConfig.cs

示例4: PostForm

        internal async Task<dynamic> PostForm(
            IEnumerable<KeyValuePair<string, string>> formParameters,
            string path, DelegatingHandler[] handlers, IEnumerable<KeyValuePair<string, string>> headerParameters = null, bool shouldRetry = true)
        {
            using (var client = HttpClientFactory.Create(handlers == null
                        ? new DelegatingHandler[] { new UserAgentHandler() }
                        : handlers.ToArray()))
            {
                var uri = _baseAddress + path;
                var httpResponse =
                    await client.PostAsync(uri, new FormUrlEncodedContent(formParameters));

                try
                {
                    return await HandleResponse(httpResponse);
                }
                catch (UnauthorizedException)
                {
                    if (shouldRetry)
                    {
                        _credentials.ResetAccessToken();
                        using (var retryClient = HttpClientFactory.Create(await GetHandlers(headerParameters)))
                        {
                            httpResponse = await retryClient.PostAsync(uri, new FormUrlEncodedContent(formParameters));
                            return await HandleResponse(httpResponse);
                        } 
                    }
                    throw;
                }
            }
        }
开发者ID:CaseyMacPherson,项目名称:gettyimages-api_dotnet,代码行数:31,代码来源:WebHelper.cs

示例5: CreateEncryptedRoute

        private void CreateEncryptedRoute(HttpConfiguration configuration)
        {
            var section = (NameValueCollection)ConfigurationManager.GetSection("Api2CryptoGraphySettings");
            if (section == null)
            {
                throw new ApplicationException("Config section 'RestfulWebService' has not been set.");
            }

            // arrange.
            var settings = new CryptoGraphySettings(section);
            var cryptoHandler = new ServerCryptoHandler(settings.SecretKey, settings.InitialVector, settings.HashKey);
            var injection = new DelegatingHandler[] { new ServerMessageDumper(), cryptoHandler }; // dump decrypted request & plain response.
            var handler = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(configuration), injection);

            // register encrypted HTTP route.
            configuration.Routes.MapHttpRoute("Encrypted Route", "api2/{controller}/{action}", null, null, handler);

            // register timestamp as a route.
            var timestampProvider = new DefaultTimestampProvider(TimeSpan.FromMinutes(15)) as ITimestampProvider<string>;
            var timestampHandler = new HttpTimestampHandler<string>(timestampProvider);
            configuration.Routes.MapHttpRoute("Timestamp Route", "api3/!timestamp!/get", null, null, timestampHandler);

            // register global timestamp service, it should align with encrypted HTTP route or will not work.
            configuration.MessageHandlers.Add(new HttpTimestampHandler<string>(configuration, "api2/!timestamp!/get", timestampProvider));
        }
开发者ID:jacktsai,项目名称:ApiFoundation,代码行数:25,代码来源:Global.asax.cs

示例6: MessageHandlerTracer

        public MessageHandlerTracer(DelegatingHandler innerHandler, ITraceWriter traceWriter)
        {
            Contract.Assert(innerHandler != null);
            Contract.Assert(traceWriter != null);

            _innerHandler = innerHandler;
            _traceWriter = traceWriter;
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:8,代码来源:MessageHandlerTracer.cs

示例7: GetChains

 private IEnumerable<string> GetChains(DelegatingHandler handler)
 {
     yield return handler.GetType().FullName;
     var innerHander = handler.InnerHandler as DelegatingHandler;
     if (innerHander != null)
     {
         yield return innerHander.GetType().FullName;
     }
 }
开发者ID:BarlowDu,项目名称:WebAPI,代码行数:9,代码来源:DemoController.cs

示例8: RetryDelegatingHandler

 /// <summary>
 /// Initializes a new instance of the <see cref="RetryDelegatingHandler"/> class. 
 /// </summary>
 /// <param name="retryPolicy">Retry policy to use.</param>
 /// <param name="innerHandler">Inner http handler.</param>
 public RetryDelegatingHandler(RetryPolicy retryPolicy, DelegatingHandler innerHandler)
     : base(innerHandler)
 {
     if (retryPolicy == null)
     {
         throw new ArgumentNullException("retryPolicy");
     }
     RetryPolicy = retryPolicy;
 }
开发者ID:markcowl,项目名称:autorest,代码行数:14,代码来源:RetryDelegatingHandler.cs

示例9: CreateBatchRestClient

        protected override BatchServiceClient CreateBatchRestClient(string url, string accountName, string key, DelegatingHandler handler = default(DelegatingHandler))
        {
            // Add HTTP recorder to the BatchRestClient
            HttpMockServer mockServer = HttpMockServer.CreateInstance();
            mockServer.InnerHandler = new HttpClientHandler();

            BatchServiceClient restClient = base.CreateBatchRestClient(url, accountName, key, mockServer);

            return restClient;
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:10,代码来源:ScenarioTestContext.cs

示例10: RegisterEncryptedRoute

        private void RegisterEncryptedRoute(HttpConfiguration configuration, ITimestampProvider<string> timestampProvider)
        {
            // arrange.
            var cryptoHandler = new ServerCryptoHandler("secretKeyPassword", "initialVectorPassword", "hashKeyString", timestampProvider);
            var injection = new DelegatingHandler[] { new ServerMessageDumper(), cryptoHandler, new ServerMessageDumper() };
            var handler = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(configuration), injection);

            // register encrypted HTTP route.
            configuration.Routes.MapHttpRoute("Encrypted API", "api2/{controller}/{action}", null, null, handler);
        }
开发者ID:jacktsai,项目名称:ApiFoundation,代码行数:10,代码来源:EncryptedHttpRouteWrapper.cs

示例11: ExecuteRequest

            public HttpResponseMessage ExecuteRequest(DelegatingHandler testTarget, HttpRequestMessage requestMessage)
            {
                testTarget.InnerHandler = new OKHandler();
                InnerHandler = testTarget;

                var requestTask = SendAsync(requestMessage, new CancellationToken());

                requestTask.Wait(5000); // 5 second timeout - tests should be quicker than this, but better than infinite for now

                return requestTask.Result;
            }
开发者ID:aehyok,项目名称:WebAPIContrib,代码行数:11,代码来源:MessageHandlerTester.cs

示例12: BasicAuthenticationHandler

        public BasicAuthenticationHandler(DelegatingHandler innerChannel, IUserValidation userValidation, string realm)
            : base(innerChannel)
        {
            if (userValidation == null)
                throw new ArgumentNullException("userValidation");

            if (string.IsNullOrEmpty(realm))
                throw new ArgumentNullException("realm");

            this.userValidation = userValidation;
            this.realm = realm;
        }
开发者ID:ChrisMissal,项目名称:WcfWebApiContrib,代码行数:12,代码来源:BasicAuthenticationHandler.cs

示例13: GetHandlerChain

 /// <summary>
 /// 获得MyHttpServer牵头的HttpMessageHandler链
 /// </summary>
 /// <param name="handler"></param>
 /// <returns></returns>
 private IEnumerable<string> GetHandlerChain(DelegatingHandler handler)
 {
     yield return handler.GetType().Name;
     while (null != handler.InnerHandler)
     {
         yield return handler.InnerHandler.GetType().Name;
         handler = handler.InnerHandler as DelegatingHandler;
         if (null == handler)
         {
             break;
         }
     }
 }
开发者ID:chenboyi081,项目名称:asp-net-web-api-2-samples,代码行数:18,代码来源:DemoController.cs

示例14: ExecuteRequest

            public HttpResponseMessage ExecuteRequest(DelegatingHandler testTarget, HttpRequestMessage requestMessage)
            {
                testTarget.InnerHandler = new OKHandler();
                InnerHandler = testTarget;

                var requestTask = SendAsync(requestMessage, new CancellationToken());

                while (!requestTask.IsCompleted)
                {
                }

                return requestTask.Result;
            }
开发者ID:AlexZeitler,项目名称:WebAPIContrib,代码行数:13,代码来源:MessageHandlerTester.cs

示例15: Main

        static void Main(string[] args)
        {

            var baseAddress = "http://localhost:8080";
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress);
           // config.MessageHandlers.Add(new ProgressMessageHandler() { });


            // Web API 路由
            config.MapHttpAttributeRoutes();

            //全局允许CROS
            // config.EnableCors();//启用跨域


            config.Routes.MapHttpRoute
           (
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
            );
            config.MaxConcurrentRequests = 1000;
            var handlers = new DelegatingHandler[] { new PassiveAuthenticationMessageHandler(), new HttpServer() };
            var routeHandlers = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(config), handlers);
            config.Routes.MapHttpRoute(
                   name: "CustomerRouter",
                  routeTemplate: "MyAPI/{Controller}/{Action}/Id",
                  defaults: new { Id = RouteParameter.Optional },
                  constraints: null,
                  handler: routeHandlers
                );
            HttpSelfHostServer server = new HttpSelfHostServer(config);
            server.OpenAsync();


            TaskManager.Instance.Initialize();
            TaskManager.Instance.Start();
           DefaultHttpBatchHandler batchHandler = new DefaultHttpBatchHandler(server);

            Console.WriteLine("Server  http://localhost:8080   Open now ....at {0}..", server.Configuration.VirtualPathRoot);
            config.EnsureInitialized();
            foreach (var route in config.Routes)
            {
                System.Diagnostics.Debug.WriteLine(route);
            }

            Console.ReadLine();

        }
开发者ID:wjkhappy14,项目名称:aspnetwebstack,代码行数:49,代码来源:Program.cs


注:本文中的System.Net.Http.DelegatingHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。