Export (0) Print
Expand All

ServiceDescription Class

Represents a complete, in-memory description of the service, including all the endpoints for the service and specifications for their respective addresses, bindings, contracts and behaviors.

System.Object
  System.ServiceModel.Description.ServiceDescription

Namespace:  System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

'Declaration
Public Class ServiceDescription

The ServiceDescription type exposes the following members.

  NameDescription
Public methodServiceDescriptionInitializes a new instance of the ServiceDescription class.
Public methodServiceDescription(IEnumerable(Of ServiceEndpoint))Initializes a new instance of the ServiceDescription class from a specified enumeration of service endpoints.
Top

  NameDescription
Public propertyBehaviorsGets the behaviors associated with the service.
Public propertyConfigurationNameGets or sets the name of the <service> configuration element.
Public propertyEndpointsGets the collection of endpoints from the service description.
Public propertyNameGets or sets the name of the service.
Public propertyNamespaceGets or sets the namespace for the service.
Public propertyServiceTypeGets the type of the service.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodStatic memberGetService(Object)Returns a service description initialized with a specified service object.
Public methodStatic memberGetService(Type)Returns a service description initialized with a specified service type.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The information contained in the ServiceDescription is used by the Windows Communication Foundation (WCF) system to building the run-time components for the service.

Use this method when adding custom behaviors to extend ServiceHost. Programmatically, you must Add(T) the custom service behavior to the Behaviors prior to when you call the Open method on the ServiceHost object.

The GetService(Object) and GetService(Type) methods are available to reflect on behaviors using the Windows Communication Foundation (WCF) programming model when replacing ServiceHostBase with you own hosting mechanism.

Export metadata about a service endpoint by passing ServiceEndpoint as a parameter to ExportEndpoint(ServiceEndpoint). After calling this method, or one of the other export methods provided by WsdlExporter, use the GeneratedWsdlDocuments property to return the collection of ServiceDescription objects.

The following example illustrates various ways to instantiate a ServiceDescription object.

			Dim baseAddress As New Uri("http://localhost:8001/Simple")
			Dim serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)

			serviceHost.AddServiceEndpoint(GetType(ICalculator), New WSHttpBinding(), "CalculatorServiceObject")

			' Enable Mex 
			Dim smb As New ServiceMetadataBehavior()
			smb.HttpGetEnabled = True
			serviceHost.Description.Behaviors.Add(smb)

			serviceHost.Open()

			' Use Default constructor 
			Dim sd As New ServiceDescription()

			' Create ServiceDescription from a collection of service endpoints 
			Dim endpoints As New List(Of ServiceEndpoint)()
			Dim conDescr As New ContractDescription("ICalculator")
			Dim endpointAddress As New EndpointAddress("http://localhost:8001/Basic")
			Dim ep As New ServiceEndpoint(conDescr, New BasicHttpBinding(), endpointAddress)
			endpoints.Add(ep)
			Dim sd2 As New ServiceDescription(endpoints)

			'// Iterate through the list of behaviors in the ServiceDescription 
			Dim svcDesc As ServiceDescription = serviceHost.Description
			Dim sbCol As KeyedByTypeCollection(Of IServiceBehavior) = svcDesc.Behaviors
			For Each behavior As IServiceBehavior In sbCol
				Console.WriteLine("Behavior: {0}", CType(behavior, Object).ToString())
			Next behavior

			' svcDesc is a ServiceDescription.
			svcDesc = serviceHost.Description
			Dim configName As String = svcDesc.ConfigurationName
			Console.WriteLine("Configuration name: {0}", configName)

			' Iterate through the endpoints contained in the ServiceDescription 
			Dim sec As ServiceEndpointCollection = svcDesc.Endpoints
			For Each se As ServiceEndpoint In sec
				Console.WriteLine("Endpoint:")
				Console.WriteLine(Constants.vbTab & "Address: {0}", se.Address.ToString())
				Console.WriteLine(Constants.vbTab & "Binding: {0}", se.Binding.ToString())
				Console.WriteLine(Constants.vbTab & "Contract: {0}", se.Contract.ToString())
				Dim behaviors As KeyedByTypeCollection(Of IEndpointBehavior) = se.Behaviors
				For Each behavior As IEndpointBehavior In behaviors
					Console.WriteLine("Behavior: {0}", CType(behavior, Object).ToString())
				Next behavior
			Next se

            Dim name = svcDesc.Name
			Console.WriteLine("Service Description name: {0}", name)

            Dim namespc = svcDesc.Namespace
			Console.WriteLine("Service Description namespace: {0}", namespc)

			Dim serviceType As Type = svcDesc.ServiceType
			Console.WriteLine("Service Type: {0}", serviceType.ToString())

			' Instantiate a service description specifying a service object 
			' Note: Endpoints collection and other properties will be null since  
			' we have not specified them 
			Dim svcObj As New CalculatorService()
			Dim sd3 As ServiceDescription = ServiceDescription.GetService(svcObj)
            Dim serviceName = sd3.Name
			Console.WriteLine("Service name: {0}", serviceName)

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft