Fast, simple test app for ADO.NET Data Services


If you're currently looking at the ADO.NET Data Services functionality that is available through the ASP.NET 3.5 Extensions Preview download, you'll notice that using the project item to add a new service is fabulously simple.


If you're not doing anything serious and just want to play around with server models and look at the wire formats, however, it is very simple to create a quick app. There is very little to add over my last post in terms of setting things up - the only extra bit I've added here is a simple class that returns some sample data (using some very nice object and collection initializers). Getting the service going is also very simple - Christian Weyer goes into more detail as to how this all works together, and Mike Taulty already found this as well.


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.Data.Web;

namespace ConsoleApplication2
{
    public class Customer
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }

    public class SampleContext
    {
        public IQueryable<Customer> Customers
        {
            get
            {
                return new List<Customer>()
                {
                    new Customer() { ID = 1, Name = "Marcelo" },
                    new Customer() { ID = 2, Name = "Andy" },
                }.AsQueryable();
            }
        }
    }

    public class SampleService : WebDataService<SampleContext>
    {
        public static void InitializeService(IWebDataServiceConfiguration c)
        {
            c.SetResourceContainerAccessRule("*", ResourceContainerRights.All);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string location = "
http://localhost:20000/";
            DataServiceHost host = new DataServiceHost(
                typeof(SampleService),
                new Uri[] { new Uri(location) });
            host.Open();
            Process p = Process.Start(location);
            if (p != null) p.Dispose();
            Console.WriteLine("Press any key to shut down the service at " + location);
            Console.ReadKey();
            host.Close();
        }
    }
}
 


This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm.

Skip to main content