The sample demonstrates how to obtain information from a typed client generated by the ServiceModel Metadata Utility Tool (Svcutil.exe). This sample is based on the Getting Started Sample that implements a calculator service. In this sample, the client is a console application (.exe) and the service is hosted by Internet Information Services (IIS).
|The setup procedure and build instructions for this sample are located at the end of this topic.|
Endpoint property allows access to information about the service endpoint that the client is communicating with—including address, binding and contract information. The client's
InnerChannel property is an instance of IClientChannel that allows access to information about the underlying channel, such as its state and session identifier.
// 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();
When you run the sample, the operation requests and responses are displayed in the client console window. Press ENTER in the client window to shut down the client.
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: http://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.
To set up, build, and run the sample
Ensure that you have performed the One-Time Setup Procedure for the Windows Communication Foundation Samples.
To build the C# or Visual Basic .NET edition of the solution, follow the instructions in Building the Windows Communication Foundation Samples.
To run the sample in a single- or cross-machine configuration, follow the instructions in Running the Windows Communication Foundation Samples.
The samples may already be installed on your machine. Check for the following (default) directory before continuing.