static void Main()
 {
     var config = new HttpHostConfiguration()
         .EnableWebLinking(reg => reg.AddLinkFrom<TheService>().To<AnotherService>("next"));
     using (var host = new WebHttpServiceHost(typeof(TheService), config, new Uri("Http://localhost:8080/linking/")))
     {
         host.Open();
         Console.WriteLine("host is opened at {0}, press any key to continue", host.BaseAddresses[0]);
         Console.ReadLine();
     }
 }
        public void ValidationModuleValidatesParameterStringAnnotations()
        {
            var config = new HttpHostConfiguration().SetProcessorProvider(new ProcessorProvider());
            var host = new PipelineHost(config, typeof (ServiceClass), "Oper", "http://host.com/");

            var uri = new Uri("http://host.com/333");
            var res = host.RunPipeline(new HttpRequestMessage(), new HttpResponseMessage(), uri);
            Assert.True(res.Get<DataValidationResult>(0).Valid);
            Assert.AreEqual("333", res.Get<string>(1));

            uri = new Uri("http://host.com/55555");
            res = host.RunPipeline(new HttpRequestMessage(), new HttpResponseMessage(), uri);
            Assert.AreEqual("55555", res.Get<string>(1));
        }
        public WebHttpServiceHost(Type serviceType, HttpHostConfiguration configuration, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        {
            this.configuration = configuration;
            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }

            if (baseAddresses == null)
            {
                throw new ArgumentNullException("baseAddresses");
            }
            this.serviceType = serviceType;
            CreateEndpoints(baseAddresses);
        }
Exemple #4
0
        public WebHttpServiceHost(Type serviceType, HttpHostConfiguration configuration, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)
        {
            this.configuration = configuration;
            if (serviceType == null)
            {
                throw new ArgumentNullException("serviceType");
            }

            if (baseAddresses == null)
            {
                throw new ArgumentNullException("baseAddresses");
            }
            this.serviceType = serviceType;
            CreateEndpoints(baseAddresses);
        }
        public WebHttpServiceHost(object singletonInstance, HttpHostConfiguration configuration, params Uri[] baseAddresses)
            : base(singletonInstance, baseAddresses)
        {
            this.configuration = configuration;
            if (singletonInstance == null)
            {
                throw new ArgumentNullException("singletonInstance");
            }

            if (baseAddresses == null)
            {
                throw new ArgumentNullException("baseAddresses");
            }

            serviceType = singletonInstance.GetType();
            CreateEndpoints(baseAddresses);
        }
Exemple #6
0
        public WebHttpServiceHost(object singletonInstance, HttpHostConfiguration configuration, params Uri[] baseAddresses)
            : base(singletonInstance, baseAddresses)
        {
            this.configuration = configuration;
            if (singletonInstance == null)
            {
                throw new ArgumentNullException("singletonInstance");
            }

            if (baseAddresses == null)
            {
                throw new ArgumentNullException("baseAddresses");
            }

            serviceType = singletonInstance.GetType();
            CreateEndpoints(baseAddresses);
        }
        static void Main(string[] args)
        {
            var provider = new ProcessorProviderFor<TheService>();
            provider.RemoveAllMediaTypeProcessors().ForResponses.OfAllOperations();

            provider.Use((o, l, m) => new ImageFromTextMediaProcessor(o, m))
                .ForResponses.OfOperation(
                    s => s.GetTimeWithConneg(default(HttpRequestMessage), default(HttpResponseMessage)));

            provider.Use((o, l, m) => new WaveFromTextMediaProcessor(o, m))
                .ForResponses.OfOperation(
                    s => s.GetTimeWithConneg(default(HttpRequestMessage), default(HttpResponseMessage)));

            provider.Use((o, l, m) =>
                    new AtomMediaTypeProcessor(o, m)
                    .WithFormatter(
                        (TheService.TimeZoneListModel tzms) => new SyndicationFeed("Time zones", "List of time zones", null,
                                                                               tzms.Zones.Select(
                                                                                   tzm =>
                                                                                   new SyndicationItem(tzm.Id, tzm.Name,
                                                                                                       new Uri(tzm.Uri)))))
                )
                .ForResponses.OfOperation(
                    s => s.GetZones(default(HttpRequestMessage), default(HttpResponseMessage)));

            provider.Use((o,l,m) => new DataValidationProcessor(o)).ForRequests.OfAllOperations();
            provider.Use((o,l,m) => new RequestLoggingProcessor(o)).ForRequests.OfAllOperations();

            var config = new HttpHostConfiguration().SetProcessorProvider(provider);

            using(var host = new WebHttpServiceHost(typeof(TheService)))
            {
                var ep = host.AddServiceEndpoint(typeof(TheService), new HttpMessageBinding(){TransferMode = TransferMode.Streamed}, "http://localhost:8080/first/");
                ep.Behaviors.Add(new HttpEndpointBehavior(config));
                host.Open();
                Console.WriteLine("host is opened at {0}, press any key to continue", ep.Address);
                Console.ReadLine();
            }
        }
        public static void AddServiceRoute <TService, TServiceHostFactory>(this RouteCollection routes, string routePrefix, HttpHostConfiguration configuration = null) where TServiceHostFactory : ServiceHostFactoryBase, IConfigurableServiceHostFactory, new()
        {
            if (routes == null)
            {
                throw new ArgumentNullException("routes");
            }

            var route = new ServiceRoute(routePrefix, new TServiceHostFactory()
            {
                Configuration = configuration
            }, typeof(TService));

            routes.Add(route);
        }
 public static void AddServiceRoute <TService>(this RouteCollection routes, string routePrefix, HttpHostConfiguration configuration = null)
 {
     AddServiceRoute <TService, WebHttpServiceHostFactory>(routes, routePrefix, configuration);
 }
 public static void Start()
 {
     var config = new HttpHostConfiguration();
     config.SetProcessorProvider(new AsyncProcessorProvider());
     using (var host = new WebHttpServiceHost(typeof(TheService), config, new Uri("Http://localhost:8080/twitter/")))
     {
         host.Open();
         Console.WriteLine("host is opened at {0}, press any key to continue", host.BaseAddresses[0]);
         Console.ReadLine();
     }
 }
Exemple #11
0
 public WebHttpServiceHost(HttpHostConfiguration configuration, params Uri[] baseAddresses)
     : base(typeof(TService), configuration, baseAddresses)
 {
 }