Esempio n. 1
0
        static void Main(string[] args)
        {
            Uri address = new Uri("http://localhost:8000/BlogService/");

            WebServiceHost svcHost = new WebServiceHost(typeof(BlogService), address);

            try
            {
                svcHost.AddServiceEndpoint(typeof(IBlog), new WebHttpBinding(), "");

                svcHost.Open();
                Console.WriteLine("Service is running");

                ChannelFactory <IBlog> factory  = new ChannelFactory <IBlog>(new WebHttpBinding(), new EndpointAddress("http://localhost:8000/BlogService/"));
                WebHttpBehavior        behavior = new WebHttpBehavior();
                factory.Endpoint.Behaviors.Add(behavior);
                IBlog client         = factory.CreateChannel();
                Rss20FeedFormatter f = (Rss20FeedFormatter)client.GetBlog("rss");

                string    serviceAddress = "http://localhost:8000/BlogService/GetBlog?format=atom";
                XmlReader reader         = XmlReader.Create(serviceAddress);

                SyndicationFeed feed = SyndicationFeed.Load(reader);

                Console.WriteLine(feed.Title.Text);
                Console.WriteLine("Items:");
                foreach (SyndicationItem item in feed.Items)
                {
                    Console.WriteLine("Title: {0}", item.Title.Text);
                    Console.WriteLine("Content: {0}", ((TextSyndicationContent)item.Content).Text);
                }

                Console.WriteLine("Press any <enter> to quit...");
                Console.ReadLine();
                svcHost.Close();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                svcHost.Abort();
            }
        }