How to Temboo with C#


Temboo makes it easy to build C# applications that connect to over 100 web-based resources and services (e.g. Facebook, Dropbox, US Census data) by standardizing how you interact with their Application Programming Interfaces (APIs). Don't worry if you're not familiar with APIs – with Temboo you don't have to worry about the details.

Here we'll show you how to use the Temboo C# SDK to write a simple C# class that uses Google's Geocoding API to retrieve the latitude and longitude for a specific address. What makes Temboo uniquely powerful and useful is that, once you know how to use one API, you know how to work with any API in our Library.

Before we get started, make sure that you've got the .NET 4.5 framework and Microsoft Visual Studio 2013 (or later) installed.

Get Set up

1 Download the Temboo C# SDK and extract the ZIP file into the directory where you keep your Visual Studio projects.

2 In Visual Studio, create a new "C# Console Application" project. For this example, name it TestProject. (The new project should automatically include a C# class file called "Program.cs" containing a Main method.)

3 Right-click the References folder under TestProject and select Add Reference. In the dialogue box that appears, select Browse and select TembooSDK.dll located in the bin folder within the extracted Temboo SDK directory. Click OK.

Test on our website

4 Log in to Temboo. If you don't already have an account, you can register for free here.

5 Go to the Google > Geocoding > GeocodeByAddress Choreo in our Library. Select C# from the drop down menu at the top of the page.

6 Enter any address or ZIP code in the Address input field e.g., 104 Franklin Street, New York City.

7 Now click Generate Code to test the Choreo from our website. After a moment you'll see the data that Google sends back shown in the Output section.

Auto-Generate The Code

When you run any Choreo from our website, we automatically generate code that can be used to make the same API call in many languages, including C#. Here we'll show you how to use these snippets in your code.

8 Scroll down to find the Code section of the Library page.

9 Copy the code snippet, and replace the contents of Program.cs with the copied code.

At this point, your code should look something like this:

using System;
using Temboo.Core;
using Temboo.Library.Google.Geocoding;

namespace TestProject
{
    class Program
    {
        static void Main(string[] args)
        {
            // Instantiate a TembooSession object using your Account name and Application key
            TembooSession session = new TembooSession("ACCOUNT_NAME", "APP_NAME", "APP_KEY");

            // Instantiate the Choreo using the TembooSession
            GeocodeByAddress geocodeByAddressChoreo = new GeocodeByAddress(session);

            // Set inputs
            geocodeByAddressChoreo.setAddress("104 Franklin St., New York NY 10013");

            // Execute Choreo
            GeocodeByAddressResultSet geocodeByAddressResults = geocodeByAddressChoreo.execute();

            // Print results
            Console.WriteLine(geocodeByAddressResults.Latitude);
        }
    }
}

Print results

At this point, the app is ready to run but by default it will exit the console session immediately. To make sure the output is visible, let's update the code to print the results returned from Google's Geocoding service and wait for input before terminating.

Each Choreo in the C# SDK returns a ResultSet subclass that contains get methods tailored specifically to the outputs of that Choreo. Using the ResultSet, you can retrieve the raw data (typically XML or JSON) returned by a third-party API or relevant fields that we've parsed out of the response for you.

10 Update the the Main method in your class, so that the final lines look like:

// Print results
Console.WriteLine("Latitude: " + geocodeByAddressResults.Latitude);
Console.WriteLine("Longitude: " + geocodeByAddressResults.Longitude);
Console.WriteLine("Press any key to continue...");

Console.ReadKey();

Try It Out

11 Run the code and you will see the results in the console. Congrats! You just ran your first Choreo from our C# SDK.

What next?

Now you're ready to run any of our 2000+ Choreos in C#. You're just a few steps away from making something extraordinary.

Once you've got your code up and running, you're ready to move on and do more. From monitoring your running applications, to moving your generated Temboo code to your preferred development environment and sharing it with colleagues, collaborators and friends - we've got you covered.

Need help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.


Back