6.10.2

As usual, run the wsdl.exe utility to generate the client proxy:

wsdl /namespace:Poker http://localhost/wspok/wspokservice.asmx

This will generate the wspokservice.cs file containing definitions for both the Poker.WSPokService and Poker.GameResult classes.

All that remains is to code the simple client shown in listing 6.18.

Listing 6.18 The WSPok client

// file : WSPok.cs

// compile : csc /out:WSPok.exe WSPokService.cs WSPok.cs namespace Poker { using System;

class WSPok {

public static void Main() { new WSPok(); // start game

}

public WSPok() {

Console.WriteLine("A WebService-based poker game..."); Console.WriteLine("Hit Ctrl-c at any time to abort.\n"); service = new WSPokService(); // create poker service while (true) nextGame(); // play

}

private void nextGame() {

string dealHand = service.Deal(); // deal hand Console.WriteLine(dealHand); // display it Console.Write("Enter card numbers (1 to 5) to hold: "); string holdCards = Console.ReadLine();

// draw replacement cards...

GameResult res = service.Draw(dealHand, holdCards);

Console.WriteLine(res.Hand);

Console.WriteLine(res.Title);

Console.WriteLine("Score = {0}\n", res.Score);

}

private WSPokService service;

}

}

This is almost identical to previous simple console-based versions of the game. This time, however, most of the heavy work takes place on the Web server.