Silverlight 2 Beta 1 - Online Game and the Pain it Caused
(Apr 05 2008 - 09:45:06 PM
by Timothy Khouri
) - [print blog
The Good News
First off, I have to say that I have successfully made an "online video game", with Silverlight as the game client. I can't stress enough how overly difficult this was, and how many "the right way" paths I went down that completely failed.
Silverlight 2 Beta 1 WCF Issues
As of right now (April 5th 2008 at 11:31 PM) as I am writing this blog post, the Silverlight 2 Beta 1 that is out doesn't support "connected" WCF functionality. What I mean by this is that, while you *can* consume WCF web services, you must use basicHttp binding, which means that you lose all ability to have required sessions.
Hopefully this will be addressed when the full version is out. But as it stands right now, no duplex WCF support and no sessioned WCF support.
Silverlight 2 Beta 1 Threading Issues
Now, I will eventually tell you how I got this to work, but first you have to understand that there was a lot of pain that needs to be resolved. When I finally got connecting to my server and receiving useful data to my Silverlight app, I was ready to add "players" to my screen... then CRASH!
Silverlight 2 Beta 1 doesn't have a way for you to update the UI at all from another thread. So, that means that using any thread other than the main thread (which includes WCF or TCP sockets) to create or update your UI, it will absolutely fail. Also, there is no "Page.Invoke" method to call your needed code back on the main UI thread as there is in Windows Forms programming.
Ultimately, Good Results = Good Results
While I am disappointed in the methods I had to employ to get here, I have to show you my awesome results:
Now, this may not look like much, but these are four browser windows running Silverlight applications that ACTUALLY CONNECTED to my C# Windows Console application via TCP sockets, and was displaying my "game" objects on the screen.
As you clicked on the Silverlight page, it sent a command across the wire to the server and the little red circles were moving around!
I'll be going to bed now, but soon I'll be writing a "make your own MMORPG video game in Silverlight" article.