WebServiceHost Class
A ServiceHost derived class that compliments the Windows Communication Foundation (WCF) Web programming model.
Assembly: System.ServiceModel.Web (in System.ServiceModel.Web.dll)
If WebServiceHost finds no endpoints in the service description, it automatically creates a default endpoint at the service's base address for HTTP and HTTPS base addresses. It does not create an endpoint automatically if the user has configured an endpoint explicitly at the base address. WebServiceHost automatically configures the endpoint's binding to work with the associated Internet Information Services (IIS) security settings when used in a secure virtual directory.
When creating a default HTTP endpoint, the WebServiceHost also disables the HTTP Help page and the Web Services Description Language (WSDL) GET functionality so the metadata endpoint does not interfere with the default HTTP endpoint.
In addition, the WebServiceHost class adds the WebHttpBehavior to all endpoints that do not already have the behavior and that have a WebMessageEncodingElement. If all the operations on the service have either empty HTTP request bodies or deal with the HTTP request body as a stream, then the WebServiceHost automatically configures the appropriate content type mapper for the binding.
The following example shows how to use the WebServiceHost class to host a service that makes use of the WCF Web programming model.
<ServiceContract()> _ Public Interface ICalculator <OperationContract()> _ <WebInvoke(UriTemplate:="add?x={x}&y={y}")> _ Function Add(ByVal x As Long, ByVal y As Long) As Long <OperationContract()> _ <WebInvoke(UriTemplate:="sub?x={x}&y={y}")> _ Function Subtract(ByVal x As Long, ByVal y As Long) As Long <OperationContract()> _ <WebInvoke(UriTemplate:="mult?x={x}&y={y}")> _ Function Multiply(ByVal x As Long, ByVal y As Long) As Long <OperationContract()> _ <WebInvoke(UriTemplate:="div?x={x}&y={y}")> _ Function Divide(ByVal x As Long, ByVal y As Long) As Long <OperationContract()> _ <WebGet(UriTemplate:="hello?name={name}")> _ Function SayHello(ByVal name As String) As String End Interface Public Class CalcService Implements ICalculator Public Function Add(ByVal x As Long, ByVal y As Long) As Long Implements ICalculator.Add Return x + y End Function Public Function Subtract(ByVal x As Long, ByVal y As Long) As Long Implements ICalculator.Subtract Return x - y End Function Public Function Multiply(ByVal x As Long, ByVal y As Long) As Long Implements ICalculator.Multiply Return x * y End Function Public Function Divide(ByVal x As Long, ByVal y As Long) As Long Implements ICalculator.Divide Return x / y End Function Public Function SayHello(ByVal name As String) As String Implements ICalculator.SayHello Return "Hello " + name End Function End Class
System.ServiceModel.Channels.CommunicationObject
System.ServiceModel.ServiceHostBase
System.ServiceModel.ServiceHost
System.ServiceModel.Web.WebServiceHost
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.