wyDay blog  |  Downloads  |  Buy
LimeLM
wyBuild
Support forum
wyDay blog
wyDay Home

The wyDay blog is where you find all the latest news and tips about our existing products and new products to come.

wyDay blog

Posts in the ‘vb.net’ tag

Windows ServiceOver the last couple of months I've gotten a surprising number of questions asking about the same thing: how to debug a Windows Service like you would debug a normal Window Forms application. There are lots of hacks to pseudo-debug a Windows service like running your code from a console, or even adding a massive amount of logging throughout your code.

But what if you need to run your Windows Service as it normally runs (i.e. as an actual service) in order to track down bugs?

The good news is that's there's a little snippet of code to make debugging Windows Services a snap. The first thing to do is to add the following DebugMode() function to your app:

C#

/// <summary>Helper function to attach a debugger to the running service.</summary>
[Conditional("DEBUG")]
static void DebugMode()
{
if (!Debugger.IsAttached)
Debugger.Launch(); Debugger.Break();
}

Visual Basic .NET

''' <summary>Helper function to attach a debugger to the running service.</summary>
<Conditional("DEBUG")>
Shared Sub DebugMode()
If Not Debugger.IsAttached Then
Debugger.Launch()
End If Debugger.Break()
End Sub

When you call the newly added DebugMode() function within your Windows Service, if there isn't already a debugger attached to your service it gives you the option of adding a debugger:

Moneybookers a.k.a. Skrill

Now you can debug your service like you would a Windows Forms application. Also, because you're using the [Conditional("DEBUG")] attribute on the DebugMode() function when you compile your service in "Release" mode all the calls to the "DebugMode()" function will be removed.

Pretty cool, huh?

Moneybookers a.k.a. SkrillMoneybookers is quickly becoming a viable competitor to PayPal. And because of this our LimeLM customers have been asking for a completely automated payment form example similar to how our PayPal example works. That is, the customer enters the number of licenses they want, they click "Buy now", they enter their info on the PayPal page, then they click "Order", and a few seconds later the customer is magically sent their shiny new product key.

With PayPal this whole process is simple — just use the PayPal IPN (instant payment notification). That is, you specify an URL for PayPal to talk to once the order is complete. From there you can validate the order and take any action you like (e.g. sending product keys).

Moneybookers has a similar process except there are hardly any examples showing how to use it properly. And the example code that is on the web is riddled with very serious security vulnerabilities (SQL injections, failing to validate the order comes from Moneybookers, etc., etc.).

This article will show you how to use the Moneybookers equivalent to PayPal's IPN. That is, you'll be able to automatically generate product keys once a customer orders your software using Moneybookers. The code I post will be for both C# (ASP.NET) and PHP. If you would rather download a fully built payment form that lets you user switch between payment methods (credit card, bank transfer, PayPal, or Moneybookers), then you can signup for LimeLM and download the LimeLM Web API Pack. Here's a screenshot of what payment form example looks like:

Payment example included in the LimeLM Web API Pack

Or, you can read on for the example that's not specific to LimeLM.

Step 1. Signup for a Moneybookers test account

The first thing you need to do is get a test "merchant" account from Moneybookers. Unfortunately Moneybookers still doesn't have a streamlined process for creating a test account, and their support staff is rather surly, so follow the instructions carefully:

  1. Sign up for a Moneybookers "Business account". Do not use the same email you'll be using for your real account.
  2. Sign up for a Moneybookers "Personal account". Use a different email than the "Business account". Do not use the same email you'll be using for your real account.
  3. Contact Moneybookers and ask them to convert these 2 accounts to test accounts. It doesn't need to be a long email. Just something simple like:

    We need you to turn 2 accounts to test accounts:

    "Buyer account":
    Email: buyer-email@example.com
    Customer ID: 12456789

    "Merchant account":
    Email: merchant-email@example.com
    Customer ID: 98765421

Step 2. Create a "secret word"

In your new merchant account you'll need to create a "Secret Word" on the "Merchant tools" page:

Creating a Moneybookers secret word

Now that you've created your test Moneybookers accounts and set your secret word you're ready to add the payment form to your website.

Step 3 (option 1). Use our pre-built payment form

If you're using LimeLM you can use our pre-built payment form. Just configure a few settings, add the payment form to your site, and you're ready to go. See the "Automate license generation with Skrill (a.k.a. Moneybookers)" article.

Step 3 (option 2). Create your own payment form

If you don't want to use the pre-built payment example in the LimeLM API Pack, or you're not using C#, VB.NET, or PHP, then you can still automate your orders with Moneybookers. The first step is to add the Moneybookers payment form to your website:

<form action="https://www.moneybookers.com/app/payment.pl" method="post">
<input type="hidden" name="pay_to_email" value="merchant-email@example.com"/>
<input type="hidden" name="status_url" value="http://example.com/verify.cgi"/>
<input type="hidden" name="language" value="EN"/>
<input type="hidden" name="amount" value="Total amount (e.g. 39.60)"/>
<input type="hidden" name="currency" value="Currency code (e.g. USD)"/>
<input type="hidden" name="detail1_description" value="YourApp"/>
<input type="hidden" name="detail1_text" value="License"/>
<input type="submit" value="Pay!"/>
</form>

Change the "status_url" field to point to your script that will verify and generate the product keys and change the "pay_to_email" field to the test "merchant email" you created earlier. Then configure the price, currency code, and product name.

Optionally set your logo

You can customize the Moneybookers payment screen with your own logo. The logo must be hosted on a secure site — that is, the link must start with https:// not http://. Also, the logo must be at most 200px wide and 50px tall. If you have a logo that meets those requirements then add a "logo_url" field to your form. For example:

<input type="hidden" name="logo_url" value="https://example.com/logo.png"/>

This is an example showing what the wyDay logo looks like on the Moneybookers checkout page:

wyDay logo as seen on a Moneybookers checkout screen

Step 4. Verify the Moneybookers order

After a customer has completed their order through Moneybookers, Moneybookers will contact the script you provided in the "status_url" argument (e.g. "http://example.com/verify.cgi"). Moneybookers will POST the order information to your script and it's up to you to verify that it's a valid order and not just some hacker trying to get free product key from you.

Luckily Moneybookers gives the prescribed method for verifying orders in their gateway integration manual. Quoting from their manual:

A hidden text field called md5sig is included in the form submitted to the Merchant's server. The value of this field is a 128 bit message digest, expressed as a string of thirty-two hexadecimal digits in UPPERCASE. The md5sig is constructed by performing an MD5 calculation on a string built up by concatenating the other fields returned to the status_url. Specifically the MD5 hash is a concatenation of the following fields:

  • merchant_id
  • transaction_id
  • the uppercase MD5 value of the ASCII equivalent of the secret word submitted in the "Merchant Tools" section of the Merchant's online Moneybookers account.
  • mb_amount
  • mb_currency
  • status

PHP example code

In PHP this looks like (taken from paychecker.php):

// Validate the Moneybookers signature
$concatFields = $_POST['merchant_id']
.$_POST['transaction_id']
.strtoupper(md5('Paste your secret word here'))
.$_POST['mb_amount']
.$_POST['mb_currency']
.$_POST['status']; $MBEmail = 'merchant-email@example.com'; // Ensure the signature is valid, the status code == 2,
// and that the money is going to you
if (strtoupper(md5($concatFields)) == $_POST['md5sig']
&& $_POST['status'] == 2
&& $_POST['pay_to_email'] == $MBEmail)
{
// Valid transaction. //TODO: generate the product keys and
// send them to your customer.
}
else
{
// Invalid transaction. Bail out
exit;
}

C# (ASP.NET) example code

In C# (for ASP.NET) this involves a bit more work. First create a simple helper function that creates the uppercase MD5 hash of a string:

static string StringToMD5(string str)
{
MD5CryptoServiceProvider cryptHandler = new MD5CryptoServiceProvider();
byte[] ba = cryptHandler.ComputeHash(Encoding.UTF8.GetBytes(str)); StringBuilder hex = new StringBuilder(ba.Length * 2); foreach (byte b in ba)
hex.AppendFormat("{0:X2}", b); return hex.ToString();
}

Then, the validation code will look something like this:

// Validate the Moneybookers signature
string concatFields = Request.Form["merchant_id"]
+ Request.Form["transaction_id"]
+ StringToMD5("Paste your secret word here")
+ Request.Form["mb_amount"]
+ Request.Form["mb_currency"]
+ Request.Form["status"]; string MBEmail = "merchant-email@example.com"; // Ensure the signature is valid, the status code == 2,
// and that the money is going to you
if (Request.Form["md5sig"] == StringToMD5(concatFields)
&& Request.Form["status"] == "2"
&& Request.Form["pay_to_email"] == MBEmail)
{
// Valid transaction. //TODO: generate the product keys and
// send them to your customer.
}
else
{
// Invalid transaction. Bail out
return;
}

Step 5. Further verification, generating product keys, etc.

There's one further step of verification I didn't talk about: making sure the customer paid the correct amount. That is, verifying the "mb_amount" field is correct. For instance you don't want to send a user a product key if they only pay 1 penny instead of the full amount. Also, you can further extend the payment form and the verification code to handle quantity. But this is a bit beyond the scope of the article. If you want to see that in action then download the example payment form included in the LimeLM Web API Pack.

Once you've verified the order you can use the limelm.pkey.generate web API function to generate product keys and email them to your customer.

Step 6. Test the payment form

Now that you have everything configured you're ready to test your Moneybookers payment. Run through the complete payment process to see everything works how you expect it to work.

Step 7. Create a real Moneybookers account, change the setting

After you've finished testing your payment process you're ready to sign up for a real Moneybookers "Business account" and change the "pay_to_email" field to the email you used to create this account.

Download full example code

We have a fully built payment page for PHP and ASP.NET (for C# and VB.NET) included in the LimeLM Web API Pack (get it on your API page). If you haven't already signed up for LimeLM then sign up now. All plans have a 30-day free trial. Or, if you're just putting your toes in the water, there's even a free plan that has no time limit and doesn't require a credit card.

There are many Windows 7 controls already out there. Ive included the best open source .NET components available. If you have other great controls, add them to the comments.

For each control Ill list what versions of .NET it compiles for and what versions of Windows it will run on.

Windows Ribbon for Windows Forms

Arik Poznanski has a great series of posts about the ribbon control he wrote that wraps the Windows 7 API.

Download it now full source code & examples. Also, view his series of articles (9 of them as of today).
Works with: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)
Windows Versions: Only Windows 7


Windows API Code Pack for Microsoft .NET Framework

This is a mammoth control collection that is the work of 3 people.

Here are the major features:

  • Windows 7 Taskbar Jump Lists, Icon Overlay, Progress Bar, Tabbed Thumbnails, and Thumbnail Toolbars.
  • Windows 7 Libraries, Known Folders, non-file system containers.
  • Windows Shell Search API support, a hierarchy of Shell Namespace entities, and Drag and Drop functionality for Shell Objects.
  • Explorer Browser Control.
  • Shell property system.
  • Windows Vista and Windows 7 Common File Dialogs, including custom controls.
  • Windows Vista and Windows 7 Task Dialogs.
  • Direct3D 11.0, Direct3D 10.1/10.0, DXGI 1.0/1.1, Direct2D 1.0, DirectWrite, Windows Imaging Component (WIC) APIs. (DirectWrite and WIC have partial support)
  • Sensor Platform APIs
  • Extended Linguistic Services APIs
  • Power Management APIs
  • Application Restart and Recovery APIs
  • Network List Manager APIs
  • Command Link control and System defined Shell icons.

Download it now full source code & examples.
Compiles with: Windows Forms (.NET 3.5) & Windows Presentation Foundation (WPF)
Windows Versions: Windows Vista & Windows 7


Windows 7 Progress Bar

Windows 7 Progress Bar is an open source progress bar component that allows you to add a progress bar to your program's taskbar button. In addition, you can control the different states of the progress bar (normal, error, and paused) for Vista & Windows 7.

Download it now full source code & examples.
Compiles with: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)
Windows Versions: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7


VistaMenu

VistaMenu is a menu component that allows you to add Windows 7 and Windows Vista-style menus with icons to your program. It's written in C# and works with all .NET languages.

Download it now full source code & examples.
Compiles with: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)
Windows Versions: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7


SplitButton

SplitButton is a button control with a region that shows a context menu when clicked. It's written in C# and works with all .NET languages.

Download it now full source code & examples.
Compiles with: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)
Windows Versions: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7


LinkLabel2

LinkLabel2 is a fixed version of the Windows.Forms LinkLabel control. It features the correct system "hand" cursor, and correct font rendering.

Download it now full source code & examples.
Compiles with: Windows Forms (.NET 2.0, .NET 3.0, .NET 3.5)
Windows Versions: Windows 98, Windows 2000, Windows XP, Windows Vista, Windows 7


7 Days of Windows 7

Join me tomorrow when I talk about Finishing touches: Make your .NET app shine with professionalism. See the full list of articles in the series.