ServiceDescription Classe

Definição

Representa uma descrição na memória completa do serviço, incluindo todos os pontos de extremidade do serviço e as especificações de seus respectivos endereços, associações, contratos e comportamentos.

public ref class ServiceDescription
public class ServiceDescription
type ServiceDescription = class
Public Class ServiceDescription
Herança
ServiceDescription

Exemplos

O exemplo a seguir ilustra várias maneiras de instanciar um ServiceDescription objeto.

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)

Comentários

As informações contidas no ServiceDescription sistema do Windows Communication Foundation (WCF) são usadas para criar os componentes de tempo de execução para o serviço.

Use esse método ao adicionar comportamentos personalizados para estender ServiceHost. Programaticamente, você deve Add(T) ter o comportamento de serviço personalizado antes Behaviors de quando chamar o Open método no ServiceHost objeto.

Os GetService(Object) métodos e os GetService(Type) métodos estão disponíveis para refletir sobre comportamentos usando o modelo de programação do WCF (Windows Communication Foundation) ao substituir ServiceHostBase por seu próprio mecanismo de hospedagem.

Exportar metadados sobre um ponto de extremidade de serviço passando ServiceEndpoint como um parâmetro para ExportEndpoint(ServiceEndpoint). Depois de chamar esse método, ou um dos outros métodos de exportação fornecidos por WsdlExporter, use a GeneratedWsdlDocuments propriedade para retornar a coleção de ServiceDescription objetos.

Construtores

ServiceDescription()

Inicializa uma nova instância da classe ServiceDescription.

ServiceDescription(IEnumerable<ServiceEndpoint>)

Inicializa uma nova instância da classe ServiceDescription de uma enumeração especificada de pontos de extremidade de serviço.

Propriedades

Behaviors

Obtém os comportamentos associados ao serviço.

ConfigurationName

Obtém ou define o nome do elemento de configuração <service>.

Endpoints

Obtém a coleção de pontos de extremidade da descrição do serviço.

Name

Obtém ou define o nome do serviço.

Namespace

Obtém ou define o namespace para o serviço.

ServiceType

Obtém o tipo do serviço.

Métodos

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.

(Herdado de Object)
GetService(Object)

Retorna uma descrição de serviço inicializada com um objeto de serviço especificado.

GetService(Type)

Retorna uma descrição de serviço inicializada com um tipo de serviço especificado.

GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Aplica-se a