ServiceDescription クラス


サービスのすべてのエンドポイントと、各エンドポイントのアドレス、バインディング、コントラクト、および動作の指定を含む、メモリ内の完全なサービスの説明を表します。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

ServiceDescription オブジェクトをインスタンス化するさまざまな方法を次の例に示します。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);

    new WSHttpBinding(),

// Enable Mex
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;


// 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);
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("\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


' 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)
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(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)


に含まれる情報は、 ServiceDescription サービスの実行時コンポーネントを構築するために、Windows Communication Foundation (WCF) システムによって使用されます。The information contained in the ServiceDescription is used by the Windows Communication Foundation (WCF) system to building the run-time components for the service.

カスタム動作を追加するときにこのメソッドを使用して、ServiceHost を拡張します。Use this method when adding custom behaviors to extend ServiceHost. プログラムにより、Add(T) オブジェクトで Behaviors メソッドを呼び出すより前に、Open を実行して、カスタム サービス動作を 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.

GetService(Object)メソッドと GetService(Type) メソッドは、を独自のホスティングメカニズムに置き換えるときに、WINDOWS COMMUNICATION FOUNDATION (WCF) プログラミングモデルを使用して動作に反映させることができ ServiceHostBase ます。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.

ServiceEndpoint をパラメーターとして ExportEndpoint(ServiceEndpoint) に渡すことにより、サービス エンドポイントについてのメタデータをエクスポートします。Export metadata about a service endpoint by passing ServiceEndpoint as a parameter to ExportEndpoint(ServiceEndpoint). このメソッドまたは WsdlExporter によって提供される他のエクスポート メソッドのいずれかを呼び出した後で、GeneratedWsdlDocuments プロパティを使用して ServiceDescription オブジェクトのコレクションを返します。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.



ServiceDescription クラスの新しいインスタンスを初期化します。Initializes a new instance of the ServiceDescription class.


指定したサービス エンドポイントの列挙体から、ServiceDescription クラスの新しいインスタンスを初期化します。Initializes a new instance of the ServiceDescription class from a specified enumeration of service endpoints.



サービスに関連付けられている動作を取得します。Gets the behaviors associated with the service.


<service> 構成要素の名前を取得または設定します。Gets or sets the name of the <service> configuration element.


サービスの説明からエンドポイントのコレクションを取得します。Gets the collection of endpoints from the service description.


サービスの名前を取得または設定します。Gets or sets the name of the service.


サービスの名前空間を取得または設定します。Gets or sets the namespace for the service.


サービスの型を取得します。Gets the type of the service.



指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(継承元 Object)

既定のハッシュ関数として機能します。Serves as the default hash function.

(継承元 Object)

指定したサービス オブジェクトを使用して初期化されたサービスの説明を返します。Returns a service description initialized with a specified service object.


指定したサービス型を使用して初期化されたサービスの説明を返します。Returns a service description initialized with a specified service type.


現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(継承元 Object)

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(継承元 Object)

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(継承元 Object)