1

我正在尝试使用 Silverlight 和 WCF Duplex 创建一个回合制游戏。但我只能做一个登录页面。我被困住了,您的所有建议/帮助将不胜感激。

我对我的架构有一些疑问。

  1. 这是在 IIS 上托管我的(WCF 轮询双工)GameService 的好方法,还是我应该制作一个控制台应用程序并提供这些方法?

  2. 我在主页中调用了 2 个方法。第一个 LoginAsync 并且一旦第一个完成,我将调用第二个 GetLoggedInPlayersAsync。但是我遇到了我无法弄清楚的错误。

这是我到目前为止所拥有的

[ServiceContract(Namespace="", CallbackContract=typeof(IGameClient), SessionMode=SessionMode.Required)]
// [DeliveryRequirements(RequireOrderedDelivery=true)]
public interface IGameService
{
    [OperationContract(IsInitiating=true)]
    bool Login(Player player);

    [OperationContract(IsInitiating=false)]
    void Logout();

    [OperationContract]
    IEnumerable<Player> GetLoggedInPlayers();
}  

public interface IGameClient
{
    [OperationContract(IsOneWay=true)]
    void NotifyNewUserConnected(Player player);
}

    public Home()
    {
        InitializeComponent();

        client = Helpers.Extensions.GetGameServiceClient();
        this.Loaded += new RoutedEventHandler(Home_Loaded);

        client.GetLoggedInPlayersCompleted += new EventHandler<GetLoggedInPlayersCompletedEventArgs>(client_GetLoggedInPlayersCompleted);
        client.NotifyNewUserConnectedReceived += new EventHandler<NotifyNewUserConnectedReceivedEventArgs>(client_NotifyNewUserConnectedReceived);
        client.LoginCompleted += new EventHandler<LoginCompletedEventArgs>(client_LoginCompleted);

    }

    void Home_Loaded(object sender, RoutedEventArgs e)
    {

        // get the player
        if (Player == null)
        {
            SignInWindow window = new SignInWindow();
            window.Show();

            Player = new Player
            {
                PlayerName = window.txtName.Text
            };

            window.Closed += new EventHandler(window_Closed);


        }
    }
4

0 回答 0