WCF Data Services allows to publish your data very fast and easy. If you use Visual Studio to create the client which consumes the services, you just can have to click "add service reference" and you have the classes you need to work with the service are generated (a sample for WCF Data Service you will find in my previous post). But what if you have a bunch of services which all follows the same convention and you want to access them in a generic way? This is also as simple as accessing the service with the generated stub. As a sample service we use one which returns all the startup date and time of the service (uses EF CT4 which can be downloaded here) public class ServerInfo
{
public int ID { get; set; }
public DateTime Startup { get; set; }
}public class ServerContext : DbContext
{
public DbSet ServerInfos { get; set; }
} [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class ServerInfoService : DataService<ServerContext>
{
public static void InitializeService(DataServiceConfiguration config)
{
ServerContext conn = new ServerContext();
conn.ServerInfos.Add(new ServerInfo() { Startup = DateTime.Now });
conn.SaveChanges(); config.SetEntitySetAccessRule("*", EntitySetRights.All);
}
}Read more: Mattia Baldingers Blog
{
public int ID { get; set; }
public DateTime Startup { get; set; }
}public class ServerContext : DbContext
{
public DbSet ServerInfos { get; set; }
} [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class ServerInfoService : DataService<ServerContext>
{
public static void InitializeService(DataServiceConfiguration config)
{
ServerContext conn = new ServerContext();
conn.ServerInfos.Add(new ServerInfo() { Startup = DateTime.Now });
conn.SaveChanges(); config.SetEntitySetAccessRule("*", EntitySetRights.All);
}
}Read more: Mattia Baldingers Blog
0 comments:
Post a Comment