For simplicity of demonstration, the following shortcuts are made:
□ The seats booked by a client are simply broadcast to all connected clients. In real life, they would also be saved in database or array.
□ When new clients connect to the server, the current seat allocation status (which seats are booked and which are not) is not sent to them.
Next, double-click on the App.config
file in Solution Explorer. Change the following highlighted attributes values:
<system.serviceModel>: <services>
behaviorConfiguration='WcfTicketingService.Service1Behavior'>
<host>
<baseAddresses>
<add
baseAddress='http://localhost:8731/Design_Time_Addresses/WcfTicketingService/Service1/' />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address
supplied above -->
<endpoint address='' binding='wsHttpBinding'
...
Right-click on the App.config
file, and select Edit WCF Configuration. Expand the EndPoints
node (see Figure 20-39), and select the first [Empty Name]
node. Set its properties as follows:
Property | Value |
---|---|
Address | net.tcp://localhost:5000/TicketingService |
Binding | NetTcpBinding |

Figure 20-39
TCP is the transport protocol.
Save the app.config
file and close the configuration window. Press F5 to debug the service. In the WCF Test Client, you will see something like Figure 20-40. The error icons (represented by the exclamation symbols) are normal.

Figure 20-40
The WCF service is complete, so it's time to build the client to consume the service. Add a new Windows Forms Application project to the current solution. Name the project Client
.
Add a service reference to the ticketing WCF service. In the Add Service Reference dialog, click the Discover button and locate the Ticketing WCF service (see Figure 20-41). Click OK.

Figure 20-41
Populate Form1 with the controls shown in Figure 20-42. Set the Size
property of Form1
to 477, 387.

Figure 20-42
In the code-behind of Form1
, import the following namespace:
using System.ServiceModel;
Declare the following constants and objects:
namespace Client {
Define the SeatsOccupied()
static function within the Form1
class as follows:
public partial class Form1 : Form {
...
...
...
}
This function accepts a string containing the seats that are occupied. The format of the string is:
<column>-<row>,<column>-<row>,...
For each seat (represented by the Button control) that is booked, the background color is changed to red.
Define the SeatStatusCallback
class and implement the SeatStatus()
method as defined in the TicketingServiceCallback
interface (defined in the service):
namespace Client {
public partial class Form1 : Form {