Category: Programming

Build XNA Game Installer: ClickOnce

This guide assumes:

  • Visual Studio 2010 Professional
  • XNA Game Studio 4.0
  • Users will be Windows

This article is the first of two on how to package your XNA game into an installer for Windows environments. The first is the easier but less customizable option of using Visual Studio’s built in ClickOnce installer. ClickOnce is essentially a hand-holding tool to package up prerequisites, dependencies, manifests, and content. Additionally, it allows you to specify locations from which the users will install the package (CD, Web, Shared Drive). More conveniently, ClickOnce allows you to specify where the application should check for updates in order to automatically update the content when new versions of the application are released. For example, you could specify a URL that the application will use to check for new versions. If a new version is detected, you can specify either the same URL or a different URL to use for downloading the new content.

While ClickOnce is easy to use, it is not perfect for every scenario and can fail quite spectacularly. I have personally run into situations where users could not install updates to the application because of cryptic errors that were only resolved by completely recreating a user account in Windows (I kid you not, this is a Microsoft-sanctioned approach). Many of the errors are difficult to diagnose and the documentation does not help much when it comes to the more advanced features of ClickOnce. It is definitely convenient, but do not use it if you want customization or extendability.

That said, here is how you use ClickOnce to package your XNA game into an installer.

  1. Open your solution in Visual Studio
  2. Right click your main project -> Properties…
  3. Click Publish tab
    • Publishing Folder: local or remote path that will be the destination of the publish (example: C:DevGamesGame1Installer)
    • Installation Folder URL: optional unless you want the users to install from a location different from the publish location
    • Install Mode: Pick offline availability (users should not have to be connected to the internet to play video games!)
    • Click Application Files…
      • Make sure the Publish Status of your game files is set to Include (Auto)
      • Make sure the Publish Status of the XNA libraries is set to Prerequisite (Auto)
    • Click Prerequisites…
      • Microsoft .NET Framework 4 Client Profile
      • Microsoft XNA Framework Redistributable 4.0
      • Windows Installer 3.1
    • Click Updates…
      • Check for updates if you want your application to check for updates through ClickOnce
      • A lot of the options are self explanatory on this screen
    • Click Options…
      • Description tab
        • Publisher name: your company name
        • Suite name: optional used to define a super application that manages this one
        • Product name: the name of your game
      • Deployment tab
        • If you want to deploy to a web page, specify the URL here
        • Check the other options here if need them
      • Manifests
        • Click “Create desktop shortcut” if you want a shortcut
        • Ignore the other options unless you really need them
  4. Specify the version of this publish (you can have it auto increment if you want)
  5. Click either the Publish wizard (which just confirms your already entered information) or Publish Now to begin publish

Your published files will be organized like this:

  • Application Files
    • Contains every version that has been published (in case user needs to rollback to a previous version)
    • Contains “Content” folder which includes files from your Content project in your XNA solution
    • .dll
Read more

Free/Busy Data from Exchange Web Services via Java

Exchange Server 2007 and 2010 offer web services that can be accessed via standard SOAP messages. This post will hopefully help you in consuming a very specific web service operation (free/busy data) from your Java environment. I expect that you can take the information found in this post and extend it to other operations. Please note that I will not discuss how to setup Exchange Web Services and will instead assume that such a service is already operational and online.

I cannot guarantee that this is the best, fastest, or most efficient way to get this working. These are the steps that I have compiled through self-teaching, reading various Microsoft documentation, and sifting through a large amount of blogs on separate issues that collectively guided me to the solution. Unlike most of the guides I found, this post should take you from the beginning of the coding process all the way to the end.

The first step is to obtain the WSDL and XSD files that describe the Exchange Web Services. These are usually hosted in the same location as the actual ASMX web service. I only have experience with the setup I use at my company, so results my differ for your Exchange setup.

  • Download Services.wsdl to local folder from URL to Exchange Web Service (ie.
  • Download messages.xsd to local folder from URL to Exchange Web Service (ie.
  • Download types.xsd to local folder from URL to Exchange Web Service (ie.

Microsoft likes to make things complicated and this is true with the files we just downloaded. The WSDL does not contain a ‘services’ tag so the importer we use to create the proxy classes will not work properly.

  • Edit the Services.wsdl file and add the following as the last tag in the main tag.
<wsdl:service name="ExchangeWebService"<wsdl:port name="ExchangeWebPort" binding="tns:ExchangeServiceBinding"<soap:address location="" /</wsdl:port</wsdl:service
  • Download this XSD file to the same directory as the above three:
  • Edit the types.xsd file that we downloaded by changing the <import namespace> tag to the following:
<xs:import namespace=“” schemaLocation=“xml.xsd”/
  • Edit Services.wsdl by adding <services> section to end. See [1] for tag to add to .wsdl.
  • Edit types.xsd to point to correct xml.xsd schema. <xs:import namespace=“” schemaLocation=“xml.xsd”/>

Alright, enough editing, time to create the proxy classes so that we can finally call this service.

  • Open a command prompt, change directory to the folder that contains your WSDL and XSD files from above
  • Type wsimport -keep -Xnocompile Services.wsdl -wsdllocation http://localhost/wsdl/ExchangeWebService.wsdl to generate proxy classes

wsimport is the name of the Java tool that will parse the WSDL and generate Java class files from the schema. Here is what the flags do:

  • keep: keeps the generated files
  • Xnocompile: does not create compiled .class files (you’ll see why in a second)
  • Services.wsdl: name of the WSDL file to parse
  • -wsdllocation http://localhost/wsdl/ExchangeWebService.wsdl: this will generate the proxy classes and tell them to point to this temporary and non-existent location (you’ll see why in a minute)

The generated files are in a long tree of folders.

  • Go all the way down to the messages folder
  • Edit
Read more

ASP.NET Web Services Part 2

You may have noticed that this post is about two months late. Time flies, doesn’t it? The previous post on an introduction to web services and how they work with ASP.NET provided you with a cursory glance. This post will provide you will how to implement a very basic web service both on the server side for consumption and the client side for use in an application.


  • Visual Studio 2005 or 2008
  • Basic knowledge of C#
  • Basic knowledge of ASP.NET Web Services

Step 1 – Create the ASP.NET Web Service

  • Visual Studio –> File –> New –> Project… –> Visual C# –> Web –> ASP.NET Web Service Application

Once the web service application project is created, notice that a templated web service was also created (Service1.asmx). The only section of this template to be worried about at the moment is the HelloWorld method marked with the [WebMethod] attribute. Marking methods as a [WebMethod] identifies that they will be used by an external caller through XML SOAP communication and are required to be exposed by the web service WSDL described in the previous post.

  • Make sure the HelloWorld method looks exactly like below.
public String HelloWorld()
     return "Hello World";
  • That is literally all it takes to expose a web service method to the world! Press F5 to begin debugging this application in a local web server and continue to Step 2.

Step 2 – Utilize the Exposed Web Service Methods

One thing to note is that because web services are implemented via XML, any application that can properly serialize commands into the correct format as described by the web service WSDL has the ability to utilize web services. That said, the following section will be written using a simple C# console application.

  • Visual Studio –> File –> New –> Project… –> Visual C# –> Windows –> Console Application
  • Like library references, you need to add a reference to the URL path of the hosted web service. In the case of this article, the web service is hosted locally in the previous step.
  • In the main project of the solution explorer, right click Web References –> Add New Web Reference…
  • In the URL textbox, copy and paste the URL found in your browser that popped up from Step 1 when you pressed F5 to debug.
  • Press the Go button to the right of the URL textbox to search for any exposed methods at the URL provided.
  • When found, enter a name for the Web reference in the bottom right (I named it localhost.)
  • Press add reference to allow Visual Studio to create classes that allow consumption of the web service.
  • Add the following code to the Main method. Make sure you change “localhost” to whatever you called your web reference and change Service1 to the name of your exposed web service class.
localhost.Service1 webService1 = new localhost.Service1();
  • Assuming that the web service local server is running properly from Step 1, press F5 to debug the console application.
Read more

ASP.NET Web Services

NOTE: Microsoft no longer suggests using this method of web services, but it is useful knowledge if you are supporting legacy systems or are still required to implement these features for business purposes. This method of web service is still useful for internal operations that do not require high security.

Below is an overview image of common web service architectures. It’s easiest to think of web services at “web methods” contained within a “web library” that contains methods to be executed on a server. The strength of this approach is that all communication is done in a standard XML format, regardless of the platforms communicating. This allows for brand new systems to communicate with extremely legacy systems, assuming that each system can properly implement a valid SOAP request and response according to the WSDL contract.

Client: Any application that requires consumption of whatever methods the web service is exposing.
Web Server: A process that hosts the web services for consumption.
Broker: Provides the definition of the web services being exposed.
SOAP: XML formatted request and results containing data according to the WSDL (see below.)
WSDL: Definition language describing which method to execute, what parameters the method requires, what data types the parameters are, what results will be returned from the web service, and what data type to expect back from the web service.

A common SOAP request with a body but no header. Note that the method being executed is defined in the <m:GetStockPrice> tag and the parameters passed are described in the <m:StockName> tag.

<?xml version="1.0"?> 
	xmlns:soap="" soap:encodingStyle=""> 
	<soap:Body xmlns:m="">

A common SOAP response with a body but no header. Note that the response being returned is defined in the <m:GetStockPriceResponse> tag and the return value is described in the <m:StockNamResponsee> tag.

<?xml version="1.0"?> 
	xmlns:soap="" soap:encodingStyle=""> 
	<soap:Body xmlns:m="">

Stay tuned for the next post which will include how to create a web service client and server in Visual Studio 2008 using C#.… Read more

Simple Class Declaration and Initialization with PHP5

If you’re used to classes with C#, C++, and Java, then you’re used to classes in PHP as well. If you’re brand new to classes, I suggest you read up on the definition and uses of them before trying to implement them via this tiny tutorial.

To begin, let’s create a simple class that will store information about a logged in user from a session. This class should hold the user’s username, first name, and last name to identify who it is on subsequent pages and requests. Begin by naming this class as “UserPassport” and adding the three previously described properties. They should not have default values because the class does not make sense without properties assigned during construction.

class UserPassport
	public $userName;
	public $firstName;
	public $lastName;

Expanding on this class, we need to add a constructor and a method to use these properties in a semi-meaningful manner.

class UserPassport
	public $userName;
	public $firstName;
	public $lastName;

    public function UserPassport($uName, $fName, $lName)
		$this-userName = $uName;
		$this-firstName = $fName;
		$this-lastName = $lName;

    public function displayInfo()
		$userInfo = array($this-userName, $this-firstName, $this-lastName);
		echo implode(', ', $userInfo);

There’s nothing crazy going on in the constructor. It’s a simple matter of assigning the properties values from whatever was passed in at construction. To display the information, a displayInfo method is created that places the three values in an array and splices them together separated by a comma and a single space. This value is then echoed to the output stream.

Now, this class is pretty useless if nothing is instantiating instances of it. Below is an example of how to instantiate and display the contents of our class. I used the xhtml 1.1 from The Web Standards Project to define a blank page.

function __autoload($class_name) {
	require_once $class_name . '.php';
?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
""<html xmlns=""<head<titleDisplay User Information</title</head<body<?php
	$userPassport = new UserPassport('jsmith', 'John', 'Smith');

The __autoload method is used to allow auto instantiation of classes without requiring an include statement to the .php file containing the definition. This is often useful if you are like me in the sense that you create one class per file. Without this __autoload method, we would need to have many include statements for each class that we are including. In this specific example, it is unnecessary, but still useful to know for the future.

A new userPassport object is created with initialize values of jsmith for username, John for first name, and Smith for last name. In a real world application, these values would be populated from a database based on login and stored for later use. Calling the displayInfo method on this object will result in the initialized values to be echoed between the HTML body tags as expected.

The resulting output:

jsmith, John, Smith


Read more

Creating a Professional ToolStrip in Windows Forms Part 2

In my previous post, I explained how to create the basic UI elements of a simple Windows Forms application with a nice looking vertical ToolStrip menu to host buttons and labels without ever leaving the Designer. In this post, I’ll explain how to wire up some events, load in some UserControl objects, and add a custom rendering method to style our MouseClick events on the ToolStrip buttons. We’ll begin by opening the project from our previous post. (seen here)


  • Microsoft Visual Studio 2008 (or 2005, but I wrote this using 2008)
  • .NET Framework 3.5 (or 2.0, but I wrote this using 3.5)
  • Basic x,y coordinate knowledge to draw and position rectangles
  • Intermediate knowledge of C# and Windows Forms
    • Inheritance and overrides
    • Event handling

Step 1 – Create a Custom Rendering Class

  • Right click on the Project in the Solution Explorer, Add –> New Item… –> Class (.cs).
  • Name this class customRenderer.cs and click OK.

This class is going to inherit from ToolStripProfessionalRenderer so that we can override some of the rendering methods and make them do whatever we want. In this case, however, we will only be overriding the OnRenderButtonBackground method.

public class customRenderer : ToolStripProfessionalRenderer
    protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)

By overriding this method, we can change the behavior of how backgrounds are rendered. Some conditions will need to be applied in order to enforce that custom rendering only occurs on ToolStripButton objects and only when the objects are in a Checked state. Read through the comments in the next code block in order to understand some of the sections.

public class customRenderer : ToolStripProfessionalRenderer
    protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        // check if the object being rendered is actually a ToolStripButton
        if (e.Item is ToolStripButton)
            ToolStripButton button = e.Item as ToolStripButton;

            // only render checked items differently
            if (button.Checked)
                // fill the entire button with a color (will be used as a border)
                int buttonHeight = button.Size.Height;
                int buttonWidth = button.Size.Width;
                Rectangle buttonFill = new Rectangle(Point.Empty, new Size(buttonWidth, buttonHeight));
                e.Graphics.FillRectangle(Brushes.SteelBlue, buttonFill);

                // fill the entire button offset by 1,1 and height/width subtracted by 2 used as the fill color
                int backgroundHeight = button.Size.Height - 2;
                int backgroundWidth = button.Size.Width - 2;
                Rectangle background = new Rectangle(1, 1, backgroundWidth, backgroundHeight);
                e.Graphics.FillRectangle(Brushes.LightSkyBlue, background);
            // if this button is not checked, use the normal render event
        // if this object is not a ToolStripButton, use the normal render event

Take a few minutes to read through the above block of code in order to fully understand what’s happening. Follow the bullets below for an overview:

  • When Windows renders the button background on a ToolStrip, this overridden method will be called instead.
  • Only use our custom render code if the item is a ToolStripButton object.
  • Only use our custom render code if the ToolStripButton has its Checked property set to True.
  • Now, two different rectangles are going to be created and filled in order to achieve a 1 pixel border color that differs from the body color of the rendered button.
Read more

Creating a Professional ToolStrip in Windows Forms

Ever wanted to create a professional looking menu in your Windows Forms applications complete with big buttons, nice mouse over effects, and images? Well, look no further. In this post, I’ll show you how to implement a graphical ToolStrip menu to navigate through a Single Document Interface (SDI). You’ll notice that the finished interface is rather similar to Spybot – Search and Destroy. Keep in mind that the following example is rather simple and leaves a lot of room for expansion.


  • Microsoft Visual Studio 2008 (or 2005, but I wrote this using 2008)
  • .NET Framework 3.5 (or 2.0, but I wrote this using 3.5)
  • Beginner’s Knowledge Windows Forms

Step 1 – Create the Form Shell to Host the Menu

  • Create a new Windows Forms Application Project.
  • Select Form1 and adjust it’s size in the Properties Window to 964,600 (the exact size isn’t important, but you want to leave room for other controls once the menu is operational).

Step 2 – Add the Menus

  • From the Toolbox:
    • Drag in a MenuStrip and snap it to the top of Form1 by either dragging it until the blue line snaps to the top of the form, or drop it in Form1 and set the MenuStrip object’s Dock property to Top.
    • Drag in a TableLayoutPanel to the center of the form.
      • From the submenu that pops up when you drop in the TableLayoutPanel, click “Remove Last Row.”
      • Set this new Container’s Dock property to Fill.
      • From the Toolbox, drag in a ToolStrip and drop it into the left column of the new TableLayoutPanel.
      • Click the “…” button in the Property Window for this new control’s Columns property.
      • Set Column1 width to absolute 115px and Column2 width to relative 100%.
    • Drag a ToolStrip into the left column (Column1).
      • Set its Dock property to Fill.
      • Set its LayoutStyle property to VerticalStackWithOverflow. This will cause contents to stack top to bottom.
      • Set its GripStyle property to Hidden. This is only a matter of preference.
      • Set its Padding property to 5,5,5,5. This will give space on all sides for its contents.
      • Set its ImageScalingSize property to 35, 35. This will force images on Buttons to scale to 35px by 35px.

Step 3 – Add Content to the Menus

  • Using the “Add New Item” drop down in the ToolStrip:
    • Add a Label (menu section title).
    • Add two Buttons (menu section content).
    • Add a Label (menu section title).
    • Add three Buttons (menu section content).
  • While holding control, select each Button on the ToolStrip:
    • Set their DisplayStyle property to ImageAndText. This will cause a caption to be added to the Button in addition to an image.
    • Set their TextImageRelation property to ImageAboveText. This will cause the caption to be below the Button’s image.
    • Set their CheckOnClick property to True. This will cause the button to display as pressed or checked when clicked a single time. We will make the check state mutually exclusive for all buttons on the ToolStrip so that only one button can be checked at any given time to enforce SDI behavior.
Read more