Пример #1
0
        static void Main(string[] args)
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            WebHttpBinding binding = new WebHttpBinding();
            binding.ContentTypeMapper = new RawContentTypeMapper();
            ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(Service), binding, "");
            DualModeWebHttpBehavior behavior = new DualModeWebHttpBehavior();
            behavior.DefaultOutgoingResponseFormat = WebMessageFormat.Json;
            endpoint.Behaviors.Add(behavior);
            host.Open();
            Console.WriteLine("Host opened");

            SendRequest(baseAddress + "/Add", "POST", "application/json", "{\"x\":3,\"y\":5}");
            SendRequest(baseAddress + "/Upload", "POST", "application/json", "{\"x\":3,\"y\":5}");
            SendRequest(baseAddress + "/Upload", "POST", "text/plain", "some random text");

            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
Пример #2
0
        static void Main(string[] args)
        {
            string         baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost    host        = new ServiceHost(typeof(Service), new Uri(baseAddress));
            WebHttpBinding binding     = new WebHttpBinding();

            binding.ContentTypeMapper = new RawContentTypeMapper();
            ServiceEndpoint         endpoint = host.AddServiceEndpoint(typeof(Service), binding, "");
            DualModeWebHttpBehavior behavior = new DualModeWebHttpBehavior();

            behavior.DefaultOutgoingResponseFormat = WebMessageFormat.Json;
            endpoint.Behaviors.Add(behavior);
            host.Open();
            Console.WriteLine("Host opened");

            SendRequest(baseAddress + "/Add", "POST", "application/json", "{\"x\":3,\"y\":5}");
            SendRequest(baseAddress + "/Upload", "POST", "application/json", "{\"x\":3,\"y\":5}");
            SendRequest(baseAddress + "/Upload", "POST", "text/plain", "some random text");

            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }