Video on Hosting WCF Data Service in Console Application

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


Discover more from Dhananjay Kumar

Subscribe to get the latest posts sent to your email.

Published by Dhananjay Kumar

Dhananjay Kumar is founder of NomadCoder and ng-India

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

Leave a comment

Discover more from Dhananjay Kumar

Subscribe now to keep reading and get access to the full archive.

Continue reading