型指定のあるクライアント

Download sample

このサンプルでは、Service Model Metadata Utility Tool (Svcutil.exe) で生成された型指定のあるクライアントから情報を取得する方法を示します。このサンプルは、電卓サービスを実装する「入門サンプル」に基づいています。この例では、クライアントはコンソール アプリケーション (.exe) で、サービスはインターネット インフォメーション サービス (IIS) によってホストされます。

Noteメモ :

このサンプルのセットアップ手順とビルド手順については、このトピックの最後を参照してください。

クライアントの Endpoint プロパティを使用すると、アドレス、バインディング、およびコントラクトの情報など、クライアントが通信しているサービス エンドポイントに関する情報にアクセスできます。クライアントの InnerChannel プロパティは、IClientChannel のインスタンスです。このプロパティにより、状態やセッション識別子などの、基になるチャネルに関する情報にアクセスできます。

// Create a client.
CalculatorClient client = new CalculatorClient();
...
Console.WriteLine("Client - endpoint:  " + client.Endpoint.Address);
Console.WriteLine("Client - binding:  " + client.Endpoint.Binding.Name);
Console.WriteLine("Client - contract: " + client.Endpoint.Contract.Name);

IClientChannel channel = client.InnerChannel;
Console.WriteLine("Client channel - state: " + channel.State);
Console.WriteLine("Client channel - session identifier: " + channel.SessionId);

//Closing the client gracefully closes the connection and cleans up resources.
client.Close();

このサンプルを実行する場合は、操作要求および応答はクライアントのコンソール ウィンドウに表示されます。クライアントをシャットダウンするには、クライアント ウィンドウで Enter キーを押します。

Add(100,15.99) = 115.99
Subtract(145,76.54) = 68.46
Multiply(9,81.25) = 731.25
Divide(22,7) = 3.14285714285714

Client - endpoint:  https://localhost/servicemodelsamples/service.svc
Client - binding:  WSHttpBinding
Client - contract: ICalculator
Client channel - state: Opened
Client channel - session identifier: urn:uuid:ae16fbc4-2964-4e87-9fb1-c5aa78fc567e

Press <ENTER> to terminate client.

サンプルを設定、ビルド、および実行するには

  1. Windows Communication Foundation サンプルの 1 回限りのセットアップの手順」が実行済みであることを確認します。

  2. ソリューションの C# 版または Visual Basic .NET 版をビルドするには、「Windows Communication Foundation サンプルのビルド」の手順に従います。

  3. 単一コンピュータ構成か複数コンピュータ構成かに応じて、「Windows Communication Foundation サンプルの実行」の手順に従います。

Footer image

Copyright © 2007 by Microsoft Corporation.All rights reserved.