ServiceDescription Klasse

Definition

Stellt eine vollständige, im Speicher befindliche Beschreibung des Diensts dar, einschließlich aller Endpunkte für den Dienst und Spezifikationen für die Adressen, Bindungen, Verträge und Verhalten.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.

public ref class ServiceDescription
public class ServiceDescription
type ServiceDescription = class
Public Class ServiceDescription
Vererbung
ServiceDescription

Beispiele

Im folgenden Beispiel werden verschiedene Möglichkeiten veranschaulicht, ein ServiceDescription-Objekt zu instanziieren.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);

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)

Hinweise

Die in ServiceDescription enthaltenen Informationen werden vom Windows Communication Foundation (WCF)-System verwendet, um die Laufzeitkomponenten für den Dienst zu entwickeln.The information contained in the ServiceDescription is used by the Windows Communication Foundation (WCF) system to building the run-time components for the service.

Verwenden Sie diese Methode, wenn Sie benutzerdefinierte Verhalten hinzufügen, um ServiceHost zu erweitern.Use this method when adding custom behaviors to extend ServiceHost. Das benutzerdefinierte Dienstverhalten muss den Add(T) mittels Behaviors programmgesteuert hinzugefügt werden, und zwar bevor die Open-Methode für das ServiceHost-Objekt aufgerufen wird.Programmatically, you must Add(T) the custom service behavior to the Behaviors prior to when you call the Open method on the ServiceHost object.

Die GetService(Object) - GetService(Type) Methode und die-Methode stehen zur Verfügung, um Verhalten mit dem Windows Communication Foundation (WCF) ServiceHostBase -Programmiermodell beim Ersetzen durch ihren eigenen Hostingmechanismus widerzuspiegeln.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.

Exportieren Sie Metadaten zu einem Dienstendpunkt, indem Sie ServiceEndpoint als Parameter an ExportEndpoint(ServiceEndpoint) übergeben.Export metadata about a service endpoint by passing ServiceEndpoint as a parameter to ExportEndpoint(ServiceEndpoint). Nach dem Aufrufen dieser Methode oder einer anderen von WsdlExporter bereitgestellten Exportmethode können Sie die GeneratedWsdlDocuments-Eigenschaft zum Zurückgeben der Auflistung von ServiceDescription-Objekten verwenden.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.

Konstruktoren

ServiceDescription()

Initialisiert eine neue Instanz der ServiceDescription-Klasse.Initializes a new instance of the ServiceDescription class.

ServiceDescription(IEnumerable<ServiceEndpoint>)

Initialisiert eine neue Instanz der ServiceDescription-Klasse aus einer angegebenen Enumeration von Dienstendpunkten.Initializes a new instance of the ServiceDescription class from a specified enumeration of service endpoints.

Eigenschaften

Behaviors

Ruft die dem Dienst zugeordneten Verhalten ab.Gets the behaviors associated with the service.

ConfigurationName

Ruft den Namen des <service>-Konfigurationselements ab oder legt diesen fest.Gets or sets the name of the <service> configuration element.

Endpoints

Ruft die Auflistung der Endpunkte von der Dienstbeschreibung ab.Gets the collection of endpoints from the service description.

Name

Ruft den Namen des Diensts ab oder legt diesen fest.Gets or sets the name of the service.

Namespace

Ruft den Namespace für den Dienst ab oder legt diesen fest.Gets or sets the namespace for the service.

ServiceType

Ruft den Typ des Diensts ab.Gets the type of the service.

Methoden

Equals(Object)

Bestimmt, ob das angegebene Objekt mit dem aktuellen Objekt identisch ist.Determines whether the specified object is equal to the current object.

(Geerbt von Object)
GetHashCode()

Fungiert als Standardhashfunktion.Serves as the default hash function.

(Geerbt von Object)
GetService(Object)

Gibt eine mit einem angegebenen Dienstobjekt initialisierte Dienstbeschreibung zurück.Returns a service description initialized with a specified service object.

GetService(Type)

Gibt eine mit einem angegebenen Diensttyp initialisierte Dienstbeschreibung zurück.Returns a service description initialized with a specified service type.

GetType()

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

(Geerbt von Object)
MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Geerbt von Object)
ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle Objekt darstellt.Returns a string that represents the current object.

(Geerbt von Object)

Gilt für: