Click or drag to resize

SelfHostingService Class

A base class for web service that can send and receive data over REST (Representational State Transfer) interface.
Inheritance Hierarchy
SystemObject
  SystemMarshalByRefObject
    GSF.AdaptersAdapter
      GSF.ServiceModelSelfHostingService
        GSF.Historian.DataServicesDataService
        GSF.ServiceBusServiceBusService
        GSF.Web.EmbeddedSecurityService

Namespace: GSF.ServiceModel
Assembly: GSF.ServiceModel (in GSF.ServiceModel.dll) Version: 2.4.218-beta
Syntax

The SelfHostingService type exposes the following members.

Constructors
 NameDescription
Protected methodSelfHostingService Initializes a new instance of the web service.
Top
Properties
 NameDescription
Public propertyAllowCrossDomainAccess Gets or sets flag that indicates if web services will enable cross-domain access for Silverlight and Flash applications.
Public propertyAllowedDomainList Gets or sets comma separated list of allowed domains when AllowCrossDomainAccess is true. Use * for domain wildcards, e.g., *.consoto.com.
Public propertyAutomaticFormatSelectionEnabled Gets or sets a value that determines if automatic format selection is enabled for Web HTTP bindings.
Public propertyContractInterface Gets or sets the FullName of the contract interface implemented by the web service.
Public propertyDefaultOutgoingRequestFormat Gets and sets the default outgoing request format for Web HTTP bindings.
Public propertyDefaultOutgoingResponseFormat Gets and sets the default outgoing response format for Web HTTP bindings.
Public propertyDomain Gets the AppDomain in which the Adapter is executing.
(Inherited from Adapter)
Public propertyEnabled Gets or sets a boolean value that indicates whether the web service is currently enabled.
(Overrides AdapterEnabled)
Public propertyEndpoints Gets or sets a semicolon delimited list of URIs where the web service can be accessed.
Public propertyFaultExceptionEnabled Gets or sets the flag that specifies whether a FaultException is generated when an internal server error(HTTP status code: 500) occurs for Web HTTP bindings.
Public propertyHostFile Gets or sets the path to the file where the Adapter is housed.
(Inherited from Adapter)
Public propertyIsDisposed Gets a flag that indicates whether the object has been disposed.
(Inherited from Adapter)
Public propertyJsonFaultHandlingEnabled Gets or sets a value that determines if JSON formatted fault messages should be returned during exceptions.
Public propertyMemoryUsage Gets the memory utilization of the Adapter in bytes if executing in a separate AppDomain, otherwise NaN.
(Inherited from Adapter)
Public propertyName Gets the unique identifier of the Adapter.
(Inherited from Adapter)
Public propertyPersistSettings Gets or sets a boolean value that indicates whether Adapter settings are to be saved to the config file.
(Inherited from Adapter)
Public propertyProcessorUsage Gets the % processor utilization of the Adapter if executing in a separate AppDomain otherwise NaN.
(Inherited from Adapter)
Public propertyPublishMetadata Gets or sets a boolean value that indicates whether web service metadata is to made available at all web service Endpoints.
Public propertySecurityPolicy Gets or sets the FullName of IAuthorizationPolicy to be used for securing all web service Endpoints.
Public propertyServiceEnabled Gets or sets a boolean value that indicates whether the web service is to be enabled at startup.
Public propertyServiceHost Gets the WebServiceHost hosting the web service.
Public propertySettingsCategory Gets or sets the category under which Adapter settings are to be saved to the config file if the PersistSettings property is set to true.
(Inherited from Adapter)
Public propertySingleton Gets or sets a boolean value that indicates whether the ServiceHost will use the current instance of the web service for processing requests or base the web service instance creation on InstanceContextMode specified in its ServiceBehaviorAttribute.
Public propertyStatus Gets the descriptive status of the Adapter.
(Inherited from Adapter)
Public propertyTypeName Gets or sets the text representation of the Adapter's TypeName.
(Inherited from Adapter)
Public propertyWindowsAuthentication Gets or sets a boolean value that indicates whether Windows Authentication is to be enabled.
Top
Methods
 NameDescription
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject)
Public methodDispose Releases all the resources used by the Adapter.
(Inherited from Adapter)
Protected methodDispose(Boolean) Releases the unmanaged resources used by the web service and optionally releases the managed resources.
(Overrides AdapterDispose(Boolean))
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalize Releases the unmanaged resources before the Adapter is reclaimed by GC.
(Inherited from Adapter)
Public methodGetFlashPolicy Gets policy stream for Flash applications.
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject)
Protected methodGetServiceAddress Gets an address where the ServiceHost will host the service.
Public methodGetSilverlightPolicy Gets policy stream for Silverlight applications.
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodGetUnusedPort Get an unused port number.
Public methodInitialize Initializes the web service.
(Overrides AdapterInitialize)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject)
Protected methodInitializeServiceHost Initializes the ServiceHost.
Public methodLoadSettings Loads saved web service settings from the config file if the PersistSettings property is set to true.
(Overrides AdapterLoadSettings)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject)
Protected methodOnDisposed Raises the Disposed event.
(Inherited from Adapter)
Protected methodOnExecutionException Raises the ExecutionException event.
(Inherited from Adapter)
Protected methodOnServiceHostCreated Raises the ServiceHostCreated event.
Protected methodOnServiceHostStarted Raises the ServiceHostStarted event.
Protected methodOnServiceProcessException Raises the ServiceProcessException event.
Protected methodOnStatusUpdate Raises the StatusUpdate event.
(Inherited from Adapter)
Public methodSaveSettings Saves web service settings to the config file if the PersistSettings property is set to true.
(Overrides AdapterSaveSettings)
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Events
 NameDescription
Public eventDisposed Occurs when Adapter is disposed.
(Inherited from Adapter)
Public eventExecutionException Occurs when the IAdapter encounters an Exception during execution.
(Inherited from Adapter)
Public eventServiceHostCreated Occurs when the ServiceHost has been created with the specified Endpoints.
Public eventServiceHostStarted Occurs when the ServiceHost has can process requests via all of its endpoints.
Public eventServiceProcessException Occurs when an Exception is encountered when processing a request.
Public eventStatusUpdate Occurs when the Adapter wants to provide a status update.
(Inherited from Adapter)
Top
Extension Methods
 NameDescription
Public Extension MethodGetEnumValueOrDefault Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodGetEnumValueOrDefaultT Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Top
Example
This example shows how to create a WCF service derived from SelfHostingService that is capable of hosting itself:
C#
using System.ServiceModel;
using System.ServiceModel.Web;
using GSF.ServiceModel;

namespace Services
{
    [ServiceContract()]
    public interface IService : ISelfHostingService
    {
        [OperationContract(), WebGet(UriTemplate = "/hello/{name}")]
        string Hello(string name);
    }

    public class Service : SelfHostingService, IService
    {
        public string Hello(string name)
        {
            return string.Format("Hello {0}!", name);
        }
    }
}
This example shows how to activate a WCF service derived from SelfHostingService that is capable of hosting itself:
C#
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
using Services;
using GSF.ServiceModel;

class Program
{
    static void Main(string[] args)
    {
        // Initialize web service.
        Service service = new Service();
        service.PublishMetadata = true;
        service.Endpoints = "http.soap11://localhost:4500/soap; http.rest://localhost:4500/rest";
        service.Initialize();

        // Show web service status.
        if (service.ServiceHost.State == CommunicationState.Opened)
        {
            Console.WriteLine("\r\n{0} is running:", service.GetType().Name);
            foreach (ServiceEndpoint endpoint in service.ServiceHost.Description.Endpoints)
            {
                Console.WriteLine("- {0} ({1})", endpoint.Address, endpoint.Binding.GetType().Name);
            }
            Console.Write("\r\nPress Enter key to stop...");
        }
        else
        {
            Console.WriteLine("\r\n{0} could not be started", service.GetType().Name);
        }

        // Shutdown.
        Console.ReadLine();
        service.Dispose();
    }
}
This example shows how to host a WCF service derived from SelfHostingService inside ASP.NET:
C#
<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="Services.Service">
        <endpoint address="soap" contract="Services.IService" binding="basicHttpBinding"/>
        <endpoint address="rest" contract="Services.IService" binding="webHttpBinding" behaviorConfiguration="restBehavior"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="restBehavior">
          <webHttp helpEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add relativeAddress="Service.svc" service="Services.Service, Services"/>
      </serviceActivations>
    </serviceHostingEnvironment>
  </system.serviceModel>
</configuration>
See Also