Resources



Sample Code and Libraries

C# Library for Amazon SimpleDB

Click for a printer friendly version of this document Printer Friendly Save to del.icio.us
Average Review:

C# Library for Amazon SimpleDB

Submitted By: Elena@AWS  
AWS Products Used: Amazon SimpleDB
Language(s): C#
License: Apache License 2.0

IMPORTANT: This library has been deprecated and will no longer be updated. We recommend developers switch to the new AWS SDK for .NET, which is almost identical to this library, where you’ll continue to get new feature updates and bug fixes. To learn more about the AWS SDK for .NET, and for support with migration, see http://aws.amazon.com/sdkfornet.

About this Library

  • Based on the 2009-04-15 API version.

What's New?

  • 2009-05-20: Deprecate Query and QueryWithAttributes. Please migrate to Select API
  • 2009-03-23: Support for BatchPutAttributes
  • 2008-12-26: Support empty parameter values
  • 2008-12-23: Fix for UTF8 url encoding for signature version 2
  • 2008-12-17: Support for signature version 2, DomainMetadata and Select API, https endpoint
  • 2008-08-25: Support for new API - QueryWithAttributes
  • 2008-01-18: Fixed UTF8 encoding

Prerequisites

Package Content

Directory Overview
src Source distribution of the library. All sources including code samples that demonstrate the use of the library located under this directory.

Quick Start

Library comes with C# solution and two pre-configured C# projects.
  • Amazon.SimpleDB.csproj - main library project
  • Amazon.SimpleDB.Samples.csproj - library samples project
To get started with the library, follow these steps:
  1. Extract the amazon-simpledb-2009-04-15-cs-library.zip file into a working directory.
  2. Open Amazon.SimpleDB.sln solution file in Visual Studio 2005
  3. Hit F5 key and follow on screen instruction

Running Samples

Steps to run particular sample
  • Open AmazonSimpleDBSamples.cs file under Amazon.SimpleDB.Samples project
  • Set AWS Access Key ID and AWS Secret Access Key
  • String accessKeyId = "<Your Access Key ID>";
    String secretAccessKey = "<Your Secret Access Key>";
        


  • Set request parameters. For example, find following pre-generated snippet:
  • // CreateDomainRequest request = new CreateDomainRequest();
    // @TODO: set request parameters here
    // CreateDomainSample.InvokeCreateDomain(service, request);
        


  • Uncomment first and third line and set DomainName
  • CreateDomainRequest request = new CreateDomainRequest();
    request.DomainName = "MyDomain";
    CreateDomainSample.InvokeCreateDomain(service, request);
    
        

  • Hit F5 to run sample. You should see the output similar to the following:


  •     CreateDomainResponse
            ResponseMetadata
                RequestId
                    95cdcb68-f46c-400b-8265-8c2de2a5c475
    
        


  • Experiment with other samples, examine samples sources. When ready, add library project to your solution, and use it.

Happy coding!

Making Requests to a Different Region

To make the service call to a different region, instantiate the client with the configuration object, and pass the region-specific endpoint. For example:

AmazonSimpleDB service = new AmazonSimpleDBClient
     (accessKeyId, secretAccessKey, 
      new AmazonSimpleDBConfig()
      .WithServiceURL("https://sdb.eu-west-1.amazonaws.com"));

See the Amazon SimpleDB Developer Guide for a complete list of region endpoints.

Previous Version Download

Comments, Questions or Feedback

If you have any comments, questions or feedback on the library, please start discussion here.

Discussion

The 5 most recent discussion messages. View full discussion.

asahu
Posts: 1
Registered: 5/28/09
Re: Missing amazonsimpledbconfig...?
Posted: Jun 4, 2009 9:32 AM PDT   in response to: Entertained Rea...
 
  Click to reply to this thread Reply

Hi

I want to connect to Amazon simple db from my c# TCP application.but
How can i connect with the Access Key id and Secert Access Key to the server(Data base).And save data in the data base.

Can anybody help me?

Thanks




alexu
Posts: 16
Registered: 5/30/07
Re: Encoding problem with C# Library for Amazon SimpleDB
Posted: May 21, 2009 8:41 PM PDT   in response to: Elena@AWS
 
  Click to reply to this thread Reply

This library DOES NOT take into account BASE64 encoded fields

here is a sample response from SimpleDB that gets handled incorrectly. Correct behavior - Attribute Name2 should be BASE64 decoded

-------------------
<?xml version=\"1.0\"?>\n<GetAttributesResponse xmlns=\" http://sdb.amazonaws.com/doc/2007-11-07/\">
<GetAttributesResult><Attribute><Name>Name</Name>
<Value>ASDF</Value></Attribute><Attribute><Name>Name3</Name>
<Value>~!@#$%^&amp;*()_+\"'|}{:?&gt;&lt;&amp;&amp;??KUKI</Value>
</Attribute><Attribute><Name>Floater</Name><Value>000000000.987</Value>
</Attribute><Attribute><Name>ItemType</Name><Value>Value1</Value>
</Attribute><Attribute><Name>Counter</Name><Value>0000000099</Value>
</Attribute><Attribute><Name>Id</Name>
<Value>0c01fa34-9a24-4833-802b-d3738771cecd</Value>
</Attribute><Attribute><Name>Counter64</Name>
<Value>000000010000000000</Value></Attribute><Attribute><Name>Name2</Name><Value encoding=\"base64\">fiFAIyQlXiYqKClfKyInfH17Oj8+PCYmPz9BCgANCVNERg==
</Value></Attribute><Attribute><Name>CreatedAt</Name>
<Value>2009-05-21T03:32:45.234</Value></Attribute></GetAttributesResult>
<ResponseMetadata><RequestId>6b749970-fb1f-7557-10d9-f144129d810c
</RequestId><BoxUsage>0.0000094822</BoxUsage></ResponseMetadata>
</GetAttributesResponse>"


redth
Posts: 1
Registered: 5/29/09
Re: Missing amazonsimpledbconfig...?
Posted: Jun 11, 2009 12:54 PM PDT   in response to: asahu
 
  Click to reply to this thread Reply

I had issues getting this running on mono 2.4 at first.

I kept getting a "error writing request" error which bubbled up from the Http Web Request.

Basically, by default, mono doesn't 'Trust' any ssl certificates.  You can either use moztool to fix this, or if you aren't too concerned about it, you can just 'override' it in your code.

using System.Net;
using System.Security.Cryptography.X509Certificates;

namespace Amazon.SimpleDB
{
    public class CustomPolicy : ICertificatePolicy
    {
        public bool CheckValidationResult(ServicePoint srvPoint,
            X509Certificate certificate,
            WebRequest request,
            int certificateProblem)
        {

            //Return True to force the certificate to be accepted.
            return true;

        }
    }
}

Make that class file, and then in the constructor of AmazonSimpleDBClient, have this:

/// <summary>
        /// Constructs AmazonSimpleDBClient with AWS Access Key ID and AWS Secret Key
        /// </summary>
        /// <param name="awsAccessKeyId">AWS Access Key ID</param>
        /// <param name="awsSecretAccessKey">AWS Secret Access Key</param>
        /// <param name="config">configuration</param>
        public AmazonSimpleDBClient(String awsAccessKeyId, String awsSecretAccessKey, AmazonSimpleDBConfig config)
        {
            this.awsAccessKeyId = awsAccessKeyId;
            this.awsSecretAccessKey = awsSecretAccessKey;
            this.config = config;

            //Fix for mono trust issues
            System.Net.ServicePointManager.CertificatePolicy = new CustomPolicy();
        }



This simply forces the client to accept the certificate no matter what.  Hope this helps anyone else trying to get it running on mono!


VR
Posts: 1
Registered: 8/25/09
Re: Encoding problem with C# Library for Amazon SimpleDB
Posted: Aug 25, 2009 10:23 PM PDT   in response to: alexu
 
  Click to reply to this thread Reply

Try using the following syntax for names that contain periods:

SELECT * FROM `my.multipart.name` WHERE attribute='someValue'

Notice the domain name is enclosed in the backward angled tick (below the ~ on most keyboards) while the 'someValue' is enclosed in the single quote (below the "  on most keyboards).

This has worked for me when I have a period in the domain name. Message was edited by: hjqcge352

jrperina
Posts: 2
Registered: 9/10/09
Re: Missing amazonsimpledbconfig...?
Posted: Oct 3, 2009 4:13 PM PDT   in response to: redth
 
  Click to reply to this thread Reply

Super big thank you redth! You are a hero... fixed my problem straight away.


Reviews
Create Review Write a Review

It Works, Oct 20, 2008 9:29 AM
Reviewer: jimkcx
The release notes provide brief and well written instructions for trying it out. The code worked as advertised. Please note that I didn't test any other functionality or form an opinion on how well the code is written (didn't even look at it--don't have time). So 5 stars for a very narrow, but critical, test. Well done to the author. Thanks for sharing.
Welcome, Guest Help
Login Login