WCF REST Service Console Host
I have a c# REST webservice that has a console host for debugging purposes. I need to add authentication mode to this service, my console host code looks like this:
WebServiceHost host = new WebServiceHost(typeof(WebService,new U开发者_C百科ri[] { new(http://localhost:8000/")});
WebHttpBinding binding = new WebHttpBinding();
host.AddServiceEndPoint(typeof(WebService, binding, "");
host.Open();
Console.WriteLine("Testing Webservice through console. Press Enter to quit.");
Console.ReadLine();
host.Close(System.TimeSpan.Zero);
The authentication in web.config can be added by:
<system.web><authentication mode="Windows"/></system.web>
How can i add authentication mode to my console host?
When an application is running in IIS, it uses web.config to store settings. When you have a desktop application (ie a console app like yours), the same settings are stored in App.config.
Just go to 'Add New Item' and select 'Application Configuration File'. This will create an App.config file in your project, which is where you can put the WCF configuration.
精彩评论