MyDataService.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.ServiceModel;

using System.ServiceModel.Web;

using System.Data.Services;

using System.Data.Services.Common;

namespace DemoHostingInConsole

{

public class MyDataService : DataService<StudentDBEntities>

{

public static void InitializeService(DataServiceConfiguration config)

{

config.SetEntitySetAccessRule("*", EntitySetRights.All);

config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;

}

}

}


Program.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.ServiceModel;

using System.ServiceModel.Web;

using System.Data.Services;

using System.Data.Services.Common;

namespace DemoHostingInConsole

{

class Program

{

static void Main(string[] args)

{

WebServiceHost host = new WebServiceHost(typeof(MyDataService),

new Uri("http://localhost:9786/MyService"));

WebHttpBinding binding = new WebHttpBinding();

host.AddServiceEndpoint(typeof(IRequestHandler), binding, "abc");

host.Open();

Console.WriteLine("Service is running at http://localhost:9786/MyService ");

Console.WriteLine("To stop the service press a Key ");

Console.ReadKey();

host.Close();

}

}

}

I hope post was useful. Happy Coding

Advertisements

2 thoughts on “Video on Hosting WCF Data Service in Console Application

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s