System.ServiceModel.Descrip ...


.NET Framework クラス ライブラリ
ServiceDescription クラス

更新 : 2007 年 11 月

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

名前空間 :  System.ServiceModel.Description
アセンブリ :  System.ServiceModel (System.ServiceModel.dll 内)
構文

Visual Basic (宣言)
Public Class ServiceDescription
Visual Basic (使用法)
Dim instance As ServiceDescription
C#
public class ServiceDescription
Visual C++
public ref class ServiceDescription
J#
public class ServiceDescription
JScript
public class ServiceDescription
解説

ServiceDescription に含まれる情報は、サービスの実行時コンポーネントを構築するために Windows Communication Foundation (WCF) システムによって使用されます。

カスタム動作を追加するときにこのメソッドを使用して、ServiceHost を拡張します。プログラムにより、ServiceHost オブジェクトで Open メソッドを呼び出すより前に、Add(T) を実行して、カスタム サービス動作を Behaviors に追加する必要があります。

GetService(Object) メソッドと GetService(Type) メソッドは、ServiceHostBase を独自のホスティング メカニズムと置き換える場合に、Windows Communication Foundation (WCF) プログラミング モデルを使用する動作に反映させるために使用できます。

ServiceEndpoint をパラメータとして ExportEndpoint(ServiceEndpoint) に渡すことにより、サービス エンドポイントについてのメタデータをエクスポートします。このメソッドまたは WsdlExporter によって提供される他のエクスポート メソッドのいずれかを呼び出した後で、GeneratedWsdlDocuments プロパティを使用して ServiceDescription オブジェクトのコレクションを返します。


ServiceDescription オブジェクトをインスタンス化するさまざまな方法を次の例に示します。

C#
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());
//}

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);

継承階層

System..::.Object
  System.ServiceModel.Description..::.ServiceDescription
スレッド セーフ

この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォーム

Windows Vista, Windows XP SP2, Windows Server 2003

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
バージョン情報

.NET Framework

サポート対象 : 3.5、3.0
参照

参照

タグ :


Page view tracker