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)); }
private void RegisterTimestampRoute(HttpConfiguration configuration, ITimestampProvider<string> timestampProvider) { // arrange. var timestampHandler = new HttpTimestampHandler<string>(timestampProvider); //var injection = new DelegatingHandler[] { new ServerMessageDumper() }; //var handler = HttpClientFactory.CreatePipeline(timestampHandler, injection); var handler = timestampHandler; // register timestamp route. configuration.Routes.MapHttpRoute("Timestamp Route", "api3/!timestamp!/get", null, null, handler); }