static void Main(string[] args) { var serviceLocator = new ServiceLocator(CreateDIContainer()); var baseurl = new Uri("http://localhost:1000/"); var serverState = new ServerState(); serverState["Hello"] = "World"; var config = new HttpConfiguration(); config.CreateInstance = (type, context, request) => serviceLocator.GetInstance(type); config.RequestHandlers = (handlers, se, od) => handlers.Add(new ServerStateOperationHandler(serverState)); config.ResponseHandlers = (handlers, se, od) => { handlers.Add(new LoggingOperationHandler(new Logger())); handlers.Add(new CompressionHandler()); }; config.Formatters.Insert(0, new JsonMediaTypeFormatter()); HttpServiceHost host = new HttpServiceHost(typeof(FooService), config, baseurl); host.Open(); Console.WriteLine("Host open. Hit enter to exit..."); Console.WriteLine("Use a web browser and go to " + baseurl + " or do it right and get fiddler!"); Console.Read(); host.Close(); }
public static void Run() { var config = new HttpConfiguration(); config.RequestHandlers += (coll, ep, desc) => { if ( desc.Attributes.Any(a => a.GetType() == typeof(JsonExtractAttribute)) ) { coll.Add(new JsonExtractHandler(desc)); } }; using (var sh = new HttpServiceHost(typeof(TheService), config, "http://localhost:8080")) { sh.Open(); Console.WriteLine("host is opened"); var client = new HttpClient(); dynamic data = new JsonObject(); data.x = "a string"; data.y = "13"; data.z = "3.14"; var resp = client.PostAsync("http://localhost:8080/v2", new ObjectContent<JsonValue>(data, "application/json")).Result; Console.WriteLine(resp.StatusCode); } }
public void Given_command_server_runnig() { var instance = new CommandsService(); var config = ConfigurationHelper.CreateConfiguration(instance); _host = new HttpServiceHost(typeof(CommandsService), config, new Uri(URL)); _host.Open(); }
public static void Main(string[] args) { string serviceURI = ConfigurationManager.AppSettings["ServiceURI"]; HttpServiceHost host = new HttpServiceHost(typeof(RESTBlogsService), serviceURI); try { host.Open(); Console.WriteLine("Service is running..."); Console.ReadLine(); } catch(Exception ex) { Console.WriteLine("HttpServiceHost failed to open {0}", ex); } finally { if (host.State == CommunicationState.Faulted) { host.Abort(); } else { host.Close(); } } }
/// <summary> /// This was a test to see how painful it is to create a large number of service hosts. /// </summary> /// <param name="args"></param> public static void Main2(string[] args) { var serviceLocator = new ServiceLocator(CreateDIContainer()); for (int i = 0; i < 1000; i++) { var baseurl = new Uri("http://localhost:1000/service" + i); var config = new HttpConfiguration(); config.CreateInstance = (type, context, request) => serviceLocator.GetInstance(type); config.RequestHandlers = (handlers, se, od ) => handlers.Add(new ServerStateOperationHandler(null)); config.ResponseHandlers = (handlers, se, od) => { handlers.Add(new LoggingOperationHandler(new Logger())); handlers.Add(new CompressionHandler()); }; var host = new HttpServiceHost(typeof(FooService), config, baseurl); host.Open(); Console.WriteLine("Opening host open " + baseurl); } Console.WriteLine("Host open. Hit enter to exit..."); // Console.WriteLine("Use a web browser and go to " + baseurl + " or do it right and get fiddler!"); Console.Read(); // host.Close(); }
public CruiseCompatibleBuildServerStub(string name) : base(name, new Uri("http://localhost:8095/" + name + "/cc.xml")) { this.serviceHost = new HttpServiceHost( new CruiseControlWebService(this), BaseUri); serviceHost.Open(); }
static void Main(string[] args) { var host = new HttpServiceHost(typeof(MyService), new Uri("http://localhost:1234")); host.Open(); Console.WriteLine("Browse to http://localhost:1234"); Console.ReadLine(); }
static void Main(string[] args) { var host = new HttpServiceHost(typeof(GitHubServiceImpl), "http://localhost:8080/"); host.Open(); Console.WriteLine("Service is running..."); Console.ReadLine(); }
public static void Run() { using (var host = new HttpServiceHost(typeof(TheService), "http://localhost:8080/upload")) { host.Open(); Console.WriteLine("Host opened at {0}", host.Description.Endpoints[0].Address); Console.ReadKey(); } }
static void SimpleMain() { using (var host = new HttpServiceHost(typeof(TheService), "http://localhost:8080")) { host.Open(); Console.WriteLine("Host opened at {0} , press any key to end", host.Description.Endpoints[0].Address); Console.ReadKey(); } }
static void Main(string[] args) { //...repositorio NancyFx/Nancy... retornar coleccao de itens=commits em formato Atom, consultando GitHub //...efeito sera' o mesmo de https://github.com/nancyfx/nancy/commits.atom ... Console.WriteLine("Inicio do Programa..."); var config = new HttpConfiguration(); //TODO : 5 de 5 - utilizar MediaTypeFormatter Formatador var host = new HttpServiceHost(typeof(Servico), config, "http://localhost:8080"); host.Open(); }
public void ServiceHost_Ctors() { // Default ctor works HttpServiceHost host = new HttpServiceHost(); // Singleton object ctor works host = new HttpServiceHost(new CustomerService(), new Uri("http://somehost")); // service type works host = new HttpServiceHost(typeof(CustomerService), new Uri("http://somehost")); }
public void ServiceHost_Explicit_Add_Endpoint_Without_Behavior() { ContractDescription cd = ContractDescription.GetContract(typeof(LocalCustomerService)); HttpServiceHost host = new HttpServiceHost(typeof(LocalCustomerService), new Uri("http://localhost")); HttpEndpoint endpoint = new HttpEndpoint(cd, new EndpointAddress("http://somehost")); endpoint.Behaviors.Clear(); Assert.AreEqual(0, endpoint.Behaviors.Count, "Expected no behaviors by default"); host.Description.Endpoints.Add(endpoint); host.Open(); Assert.AreEqual(1, endpoint.Behaviors.OfType<HttpBehavior>().Count(), "Expected open to add behavior"); }
static void HostWithHttpServiceHost() { var instance = new TodoResource(new ToDoMemoryRepository()); using (var host = new HttpServiceHost(instance, "http://localhost:8080/todo")) { host.AddServiceEndpoint(typeof(TodoResource), new HttpBinding(), "http://localhost:8080/todo2"); host.Open(); ShowEndpointsOf(host); WaitForKey(); } }
public void WhenPostingAPersonThenResponseIndicatesPersonWasAdded() { HelloResource.Initialize(new List<string>()); using (var host = new HttpServiceHost(typeof(HelloResource), this.hostUri)) { host.Open(); var client = new HttpClient(); var response = client.Post(this.hostUri, new StringContent("person=Glenn", Encoding.UTF8, "application/x-www-form-urlencoded")); Assert.AreEqual("Added Glenn", response.Content.ReadAsString()); } }
public void Given_command_server_runnig() { var instance = new CommandsService(new ServerContext ( registry: new ReflectionCommandRegistry(typeof(__SampleCommandsMarker).Assembly), broker: new LongCommandBroker() )); var config = ConfigurationHelper.CreateConfiguration(instance); _host = new HttpServiceHost(typeof(CommandsService), config, new Uri(URL)); _host.Open(); }
public static void Run() { var config = new HttpConfiguration(); config.RequestHandlers = (coll, endpoint, desc) => coll.Add(new TheOperationHandler(desc)); using (var host = new HttpServiceHost(typeof(TheService), config, "http://localhost:8080/conv")) { host.Open(); Console.WriteLine("Host opened at {0}", host.Description.Endpoints[0].Address); Console.ReadKey(); } }
static void Main(string[] args) { //using (var host = new HttpServiceHost(typeof(TheServiceClass), "http://localhost:8080/first")) //using (var host = new HttpServiceHost(typeof(TimerResource), "http://localhost:8080/first")) //using (var host = new HttpServiceHost(typeof(ProcessResource), "http://localhost:8080/procs")) using (var host = new HttpServiceHost(new TodoResource (new ToDoMemoryRepository()), "http://localhost:8080/todo")) { host.Open(); ShowEndpointsOf(host); WaitForKey(); } }
public void ServiceHost_Explicit_Add_Endpoint_Without_Behavior() { ContractDescription cd = ContractDescription.GetContract(typeof(LocalCustomerService)); HttpServiceHost host = new HttpServiceHost(typeof(LocalCustomerService), new Uri("http://localhost")); HttpEndpoint endpoint = new HttpEndpoint(cd, new EndpointAddress("http://somehost")); endpoint.Behaviors.Clear(); Assert.AreEqual(0, endpoint.Behaviors.Count, "Expected no behaviors by default"); host.Description.Endpoints.Add(endpoint); host.Open(); Assert.AreEqual(1, endpoint.Behaviors.OfType <HttpBehavior>().Count(), "Expected open to add behavior"); }
public static void Run() { using (var host = new HttpServiceHost(typeof(TheService), "http://localhost:8080/async")) { host.AddDefaultEndpoints(); var b = host.Description.Endpoints[0].Binding as HttpBinding; b.MaxBufferSize = 1*1024*1024; b.MaxReceivedMessageSize = 1*1024*1024; b.TransferMode = TransferMode.Streamed; host.Open(); Console.WriteLine("Host opened at {0}", host.Description.Endpoints[0].Address); Console.ReadKey(); } }
public void WhenGettingThenReturnsListOfPeopleAdded() { var peopleToSayHelloTo = new List<string>(); peopleToSayHelloTo.Add("Glenn"); HelloResource.Initialize(peopleToSayHelloTo); using (var host = new HttpServiceHost(typeof(HelloResource), this.hostUri)) { host.Open(); var client = new HttpClient(); var response = client.Get(this.hostUri); Assert.AreEqual("Hello Glenn", response.Content.ReadAsString()); host.Close(); } }
public static void Run() { var config = new HttpConfiguration() .UseParameterConverterFor<AComplexType>(s => new AComplexType {Value = s.ToUpper()}) .UseParameterConverterFor<AnotherComplexType>(s => new AnotherComplexType {Value = Int32.Parse(s)+1}); using (var host = new HttpServiceHost(typeof(TheService), config, "http://localhost:8080/conv")) { host.Open(); Console.WriteLine("Host opened at {0}", host.Description.Endpoints[0].Address); var client = new HttpClient(); Console.WriteLine(client.GetAsync("http://localhost:8080/conv/hello/3").Result.Content.ReadAsStringAsync().Result); } }
public void ShouldReturnRemoteAddress() { var serviceUri = new Uri("http://localhost:1017/"); var config = new HttpConfiguration(); var host = new HttpServiceHost(typeof(TestService),config, new[] { serviceUri }); host.Open(); var httpClient = new HttpClient(); httpClient.BaseAddress = serviceUri; var response = httpClient.GetAsync("ResourceA").Result; Assert.AreEqual("127.0.0.1", response.Content.ReadAsStringAsync().Result); }
public void Given_command_server_runnig() { var instance = new CommandsService(new ServerContext( registry: new FooCommandRegistry(), broker: new DelegatingCommandBroker((cmd, ctx) => { return Task.Factory.StartNew(() => { }); }))); var config = ConfigurationHelper.CreateConfiguration(instance); SimpleBasicAuthenticationHandler.Configure(config, cred => false); _host = new HttpServiceHost(typeof(CommandsService), config, new Uri(URL)); _host.Open(); }
public void ServiceHost_Works_With_OneWay_Operation() { ContractDescription cd = ContractDescription.GetContract(typeof(OneWayService)); HttpServiceHost host = new HttpServiceHost(typeof(OneWayService), new Uri("http://localhost/onewayservice")); host.Open(); using (HttpClient client = new HttpClient()) { client.Channel = new WebRequestChannel(); using (HttpResponseMessage actualResponse = client.Get("http://localhost/onewayservice/name")) { Assert.AreEqual(actualResponse.StatusCode, HttpStatusCode.Accepted, "Response status code should be Accepted(202) for one-way operation"); } } host.Close(); }
public void PostContent() { var content = new StringContent("This is some content"); content.Headers.ContentType = new MediaTypeHeaderValue("text/plain"); var serviceUri = new Uri("http://localhost:1017/"); var config = new HttpConfiguration(); var host = new HttpServiceHost(typeof(TestService), config, new[] { serviceUri }); host.Open(); var httpClient = new HttpClient(); httpClient.BaseAddress = serviceUri; var response = httpClient.PostAsync("ResourceA", content).Result; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
static void HostWithHttpsEndpoint() { var repository = new ToDoMemoryRepository(); repository.Add(new ToDo("Must learn HTTP better")); var instance = new TodoResource(repository); using (var host = new HttpServiceHost(instance, "http://localhost:8080/todo")) { host.AddServiceEndpoint(typeof(TodoResource), new HttpBinding(), "http://localhost:8080/todo"); var binding = new HttpBinding(HttpBindingSecurityMode.Transport); binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; host.AddServiceEndpoint(typeof(TodoResource), binding, "https://localhost:8435/todo"); //host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.CurrentUser,StoreName.My,X509FindType.FindBySubjectName, "gaviao"); host.Open(); ShowEndpointsOf(host); WaitForKey(); } }
public static void Run() { using (var host = new HttpServiceHost(typeof(TheService), new string[0])) { var mb = new HttpMemoryBinding(); var ep = host.AddServiceEndpoint(typeof (TheService), mb, "http://dummy-http-scheme-uri"); foreach (var op in ep.Contract.Operations) { op.Behaviors.Find<OperationBehaviorAttribute>().AutoDisposeParameters = false; } host.Open(); Console.WriteLine("Host opened at {0}", host.Description.Endpoints[0].Address); var client = new HttpClient(mb.GetHttpMemoryHandler()); // Yes, it must be async. Apparently, sync is not supported with the memory channel var aresp = client.GetAsync("http://another-dummy-http-scheme-uri/hello"); Console.WriteLine(aresp.Result.Content.ReadAsStringAsync().Result); Console.ReadKey(); } }
public void ReasonPhraseShouldBeReturnedToTheClient() { var serviceUri = new Uri("http://localtmserver:1017/"); var config = new HttpConfiguration(); var host = new HttpServiceHost(typeof(TestService),config, new[] { serviceUri }); host.Open(); var httpClient = new HttpClient(); httpClient.BaseAddress = serviceUri; string reasonPhrase = null; httpClient.GetAsync("ResourceWithReasonPhrase") .ContinueWith((t) => { reasonPhrase = t.Result.ReasonPhrase; }).Wait(); Assert.AreEqual("All Good", reasonPhrase); }
public void LoadStreamContentFromEmbeddedResource() { var content = new StreamContent(GetType().Assembly.GetManifestResourceStream(GetType(), "XForms.pdf")); //var content = new StringContent("Hwllo world"); var serviceUri = new Uri("http://localhost:1017/"); var config = new HttpConfiguration(); var host = new HttpServiceHost(typeof(TestService),config, new[] { serviceUri }); // Configure Endpoint for transferring large files host.AddDefaultEndpoints(); var endpoint = ((HttpEndpoint)host.Description.Endpoints[0]); endpoint.TransferMode = TransferMode.Streamed; endpoint.MaxReceivedMessageSize = 1024 * 1024 * 10; host.Open(); var httpClient = new HttpClient(); httpClient.BaseAddress = serviceUri; var response = httpClient.PostAsync("ResourceA",content).Result; Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
public void Given_command_server_runnig() { var instance = new CommandsService(new ServerContext ( registry: new FooCommandRegistry(), broker: new DelegatingCommandBroker((cmd, ctx) => { _postedCommand = cmd; _ctx = ctx; return Task.Factory.StartNew(() => {}); }) )); var config = ConfigurationHelper.CreateConfiguration(instance); SimpleBasicAuthenticationHandler.Configure(config, cred => cred.UserName == "supr" && cred.Password == "booper"); _host = new HttpServiceHost(typeof(CommandsService), config, new Uri(URL)); _host.Open(); // Client side var bus = new CommandBus(URL, new Client.Avanced.ZazConfiguration { ConfigureHttp = h => { h.Credentials = new NetworkCredential("supr", "booper"); } }); bus.Post(new FooCommand { Message = "Hello world" }); // Close host _host.Close(); }