You may or may not know, but I have had a load of trouble trying to implement the MS Push service that we get with XNA on the WP7, in fact, me and the service got on so badly I decided to abandon it and have a go at writing my own.
Now, this post comes with a huge warning, I am not an ASP.NET developer, in my job I am jammed firmly in the world of .NET 2.0 and I very rarely venture out from this world. So with that said, the code I am to present here in this post can almost certainly be done much better in later frameworks and by some one that has a better knowledge of ASP.NET than me. Now that my technical bottom has been covered, on with the code.
Why did I start looking at this? Well, at one of our meetings in the pub we discussed turn based games on the WP7, and I thought that this would be a great way to use the Push service. So I started down the route of creating a simple “Conquer the Stars!” type turn based game, the start of the server side stuff you can find here, but it wont be that interesting as it’s kind of on hold now while I sort out my own API.
So I think I have a mechanism that sort of works now, as I say I am no web master, so if you are clued up and think I am going about this the wrong way then please shout up and let me know.
So the basic idea now is to serve up data from generic handlers, so based on incoming query strings I can return data from the server that the client requires. As yet none of this is encrypted, either in the query string or the data being served back, but I plan to. Also I am not using SSL, yet.
For my personal hosting I use tsohost.com, mostly as it’s cheap and they support ASP.NET 4.0 so I don’t have to learn any of that crazy PHP or JSP madness, just stick to good old C# :P With this I also get up to 5 MySQL Database’s as well as some other goodies. If I want to use SSL then they charge about £50 per cert p/a So how do I access my MySQL data on the server.
Using MySQL .NET assemblies I created this class to do basic interaction with my Database.
So how do I serve data from my server? I create a generic handler, for this demo I have created only one, GetTexture.ashx. It has an instance of my DBTools class so I can (in a very basic way) authenticate calls to it.
So, it is expecting 2 parameters “usr” and “pwd” a bit like this
http://yourdomain/XNAHTTPServer/GetTexture.ashx?usr=nemo&pwd=oxosox, so if the user “nemo” with the password “oxosox” is in my User table, then the page will return a url for me to get an image asset, otherwise it will tell me I don’t have access.
In this case the image coming back from the server is this one
So, in my XNA WP7 project (will work on PC games to, but not the Xbox) I have created a HTTPRequest class to call to the server and get the url back, then once it has the url to then download the image and render it to the screen :)
So now I am able to dynamically download an asset to my game and use it. The resulting out put looks like this :) Remember, there are no assets in the XNA project at all…
Source code for both client and server can be downloaded here.
So, if you think what I am attempting is just plain crazy mental, either just the ASP.NET side of things, the security behind what I am doing, or performance or anything then please let me know :D