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)

public class ServiceDescription

The ServiceDescription type exposes the following members.

  NameDescription
Public methodServiceDescription()Initializes a new instance of the ServiceDescription class.
Public methodServiceDescription(IEnumerable<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 a hash function for a particular type. (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 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 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.


            Uri baseAddress = new Uri("http://localhost:8001/Simple");
            ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);

            serviceHost.AddServiceEndpoint(
                typeof(ICalculator),
                new WSHttpBinding(),
                "CalculatorServiceObject");

            // Enable Mex
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = true;
            serviceHost.Description.Behaviors.Add(smb);

            serviceHost.Open();

            // Use Default constructor
            ServiceDescription sd = new ServiceDescription();

            // Create ServiceDescription from a collection of service endpoints
            List<ServiceEndpoint> endpoints = new List<ServiceEndpoint>();
            ContractDescription conDescr = new ContractDescription("ICalculator");
            EndpointAddress endpointAddress = new EndpointAddress("http://localhost:8001/Basic");
            ServiceEndpoint ep = new ServiceEndpoint(conDescr, new BasicHttpBinding(), endpointAddress);
            endpoints.Add(ep);
            ServiceDescription sd2 = new ServiceDescription(endpoints);

            //// Iterate through the list of behaviors in the ServiceDescription
            ServiceDescription svcDesc = serviceHost.Description;
            KeyedByTypeCollection<IServiceBehavior> sbCol = svcDesc.Behaviors;
            foreach (IServiceBehavior behavior in sbCol)
            {
                Console.WriteLine("Behavior: {0}", behavior.ToString());
            }

            // svcDesc is a ServiceDescription.
            svcDesc = serviceHost.Description;
            string configName = svcDesc.ConfigurationName;
            Console.WriteLine("Configuration name: {0}", configName);

            // Iterate through the endpoints contained in the ServiceDescription
            ServiceEndpointCollection sec = svcDesc.Endpoints;
            foreach (ServiceEndpoint se in sec)
            {
                Console.WriteLine("Endpoint:");
                Console.WriteLine("\tAddress: {0}", se.Address.ToString());
                Console.WriteLine("\tBinding: {0}", se.Binding.ToString());
                Console.WriteLine("\tContract: {0}", se.Contract.ToString());
                KeyedByTypeCollection<IEndpointBehavior> behaviors = se.Behaviors;
                foreach (IEndpointBehavior behavior in behaviors)
                {
                    Console.WriteLine("Behavior: {0}", behavior.ToString());
                }
            }

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

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

            Type serviceType = 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
            CalculatorService svcObj = new CalculatorService();
            ServiceDescription sd3 = ServiceDescription.GetService(svcObj);
            String serviceName = sd3.Name;
            Console.WriteLine("Service name: {0}", serviceName);



.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.

Community Additions

ADD
Show:
© 2014 Microsoft