This section shows you how to create the new project, set up libraries, and define the structure of your program.
The Java project consists of one source file, and SOAP proxy classes generated by Apache Axis from the web service's WSDL file.
To create the Java project
Using your favorite text editor, create a file named DoGetAccountBalance.java.
Enter, or copy and paste, the following text into the new file:
// Import classes
public class DoGetAccountBalance {
// Define constants
// Define authentication routines
// Define other support routines
public static void main( String [] args ) {
try {
// Set up the web service client
// Construct the request
// Calculate and set the request authentication parameters
// Set other parameters
// Make the request
// Check for and print results and errors
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
Generate the SOAP proxy classes with Apache Axis.
Ensure that Apache Axis is set up properly, as described in Prerequisites.
From a command prompt, change the current working directory to your project's directory, then run the following command:
java org.apache.axis.wsdl.WSDL2Java -v -W http://mechanicalturk.amazonaws.com/AWSMechanicalTurk/2006-10-31/AWSMechanicalTurkRequester.wsdl
The generated source files are created in a new
directory: com/amazonaws/mechanicalturk/
In DoGetAccountBalance.java, add a line to
import the generated Axis classes:
// Import classes import com.amazonaws.mturk.requester.doc._2006_10_31.*;
The C# project uses the "Console Application" template
provided by Microsoft Visual C#. The code is placed in the
Program.cs file provided by the template, and
accesses the web service's SOAP interface using a .NET Web
Resource.
To create the C# project
Open Microsoft Visual C# 2006 Express Edition. If you are using another version of Microsoft Visual Studio, these steps might be slightly different.
Create a new project using the "Console Application" template.
From the File menu, select New Project... A dialog box opens.
From the available templates, select Console Application.
For the name of the project, enter
DoGetAccountBalance.
Click OK. A new
project is created with a Program.cs file
and an empty main routine.
Replace the contents of Program.cs with the following text:
// Use classes
using System;
using System.Collections.Generic;
using System.Text;
namespace DoGetAccountBalance
{
class Program
{
// Define constants
// Define authentication routines
// Define other support routines
static void Main(string[] args)
{
try
{
// Set up the web service client
// Construct the request
// Calculate and set the request authentication parameters
// Set other parameters
// Make the request
// Check for and print results and errors
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
// Pause the output so you can run this directly in Visual Studio.
Console.WriteLine("Press Enter to exit...");
Console.Read();
}
}
}
Generate the SOAP proxy classes by adding a .NET Web Reference to the project.
From the Project menu, select Add Web Reference... A dialog box opens.
For the URL, enter the URL of the web service WSDL:
http://mechanicalturk.amazonaws.com/AWSMechanicalTurk/2006-10-31/AWSMechanicalTurkRequester.wsdl
Click Go. The service WSDL is retrieved over the network.
Click Add Reference. The Web Reference classes are generated and added to the project.
In Program.cs, add a line to use the generated
Web Reference classes, as follows:
// Use classes
[...]
using DoGetAccountBalance.com.amazonaws.mechanicalturk;
The Perl project consists of one source file.
To create the Perl project
Using your favorite text editor, create a file named GetAccountBalance.pl.
Enter, or copy and paste, the following text into the new file:
#!/usr/bin/perl use strict; use warnings; # Use modules # Define constants # Define authentication routines # Calculate the request authentication parameters # Construct the request # Make the request # Check for and print results and errors
If necessary, adjust the #!/usr/bin/perl line
at the top of the file to use the path to Perl on your
system.
The PHP project consists of one source file.
To create the PHP project
Using your favorite text editor, create a file named GetAccountBalance.php.
Enter, or copy and paste, the following text into the new file:
<?php // Define constants // Define authentication routines // Calculate the request authentication parameters // Construct the request // Make the request // Check for and print results and errors ?>
The Python (REST) project consists of one source file.
To create the Python (REST) project
Using your favorite text editor, create a file named GetAccountBalance.py.
Enter, or copy and paste, the following text into the new file:
#!/usr/bin/env python # Import libraries # Define constants # Define authentication routines # Calculate the request authentication parameters # Construct the request # Make the request # Check for and print results and errors
The Python (SOAP) project consists of one source file.
To create the Python (SOAP) project
Using your favorite text editor, create a file named GetAccountBalance.py.
Enter, or copy and paste, the following text into the new file:
#!/usr/bin/env python # Import libraries # Define constants # Define authentication routines # Set up the web service client # Calculate the request authentication parameters # Make the request # Check for and print results and errors
The Ruby (REST) project consists of one source file.
To create the Ruby (REST) project
Using your favorite text editor, create a file named GetAccountBalance.rb.
Enter, or copy and paste, the following text into the new file:
#!/usr/bin/env ruby # Require libraries # Define constants # Define authentication routines # Calculate the request authentication parameters # Construct the request # Make the request # Check for and print results and errors
The Ruby (SOAP) project consists of one source file.
To create the Ruby (SOAP) project
Using your favorite text editor, create a file named GetAccountBalance.rb.
Enter, or copy and paste, the following text into the new file:
#!/usr/bin/env ruby # Require libraries # Define constants # Define authentication routines # Set up the web service client # Calculate the request authentication parameters # Construct the request # Make the request # Check for and print results and errors