Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between ServiceHost and WebServiceHost?

For .Net4, is there any difference between the following

Uri baseAddress = new Uri("http://localhost:8080/test");
ServiceHost host = new ServiceHost(typeof(TestService), baseAddress);
host.Open();

and

Uri baseAddress = new Uri("http://localhost:8080/test");
WebServiceHost host = new WebServiceHost(typeof(TestService), baseAddress);
host.Open();

all the books recommend using webServiceHost, but why I cannot see difference?

like image 502
Adam Lee Avatar asked Oct 14 '12 10:10

Adam Lee


1 Answers

The WebServiceHost class is based on the ServiceHost class.

It comes with WebHttpBinding and WebHttpBehavior by default. (The nice thing is you don't need a configuration file, for simple use.)

From MSDN:

When you use WebServiceHost instead of ServiceHost, it will automatically create a Web endpoint for you using the base HTTP address and configure the injected endpoint with the WebHttpBehavior

like image 138
Rob Dunbar Avatar answered Oct 14 '22 03:10

Rob Dunbar