I also learned we can write service model element in app.config from code. (But we don't use usually.)
I'm gonna show you sample code.
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(EvalService));
host.AddServiceEndpoint(typeof(IEvalService),
new BasicHttpBinding(),
"http://localhost:8080/evals/basic");
host.AddServiceEndpoint(typeof(IEvalService),
new WSHttpBinding(),
"http://localhost:8080/evals/ws");
host.AddServiceEndpoint(typeof(IEvalService),
new NetTcpBinding(),
"net.tcp://localhost:8081/evals");
try
{
host.Open();
PrintServiceInfo(host);
Console.ReadLine();
host.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex);
host.Abort();
Console.ReadLine();
}
}
static void PrintServiceInfo(ServiceHost host)
{
Console.WriteLine("{0} is up and running with these endpoints:",
host.Description.ServiceType);
foreach (ServiceEndpoint se in host.Description.Endpoints)
Console.WriteLine(se.Address);
}
}
The result is like this.
So remarkably, you need run visual studio as Administrator.
- WCF app.config Editor
You may feel pain to write app.config for WCF. There is excellent configuration tool for you.
You can easily edit app.config from GUI.



No comments:
Post a Comment