views:

356

answers:

3

http://www.dscredstorm.com/getisbninfo.aspx

I'm trying to use Amazon's api. I downloaded their example code, which is a C# windows form app but I figured it should work for a C# website also, correct?

SignedRequestHelper.cs is a file that appears to have some functionality that I need to send a signed request. It's namespace is AmazonProductAdvtApi. I put the file in App_Code/Csharp and I added 'using AmazonProductAdvtApi;' to my page.

But I get this error: 'AmazonProductAdvtApi.SignedRequestHelper' is inaccessible due to its protection level

Why?

More info: SignedRequestHelper helper = new SignedRequestHelper(accessKeyId, secretKey, destination);

See: http://www.dscredstorm.com/getisbninfo.aspx

Here is the class declaration for SignedRequestHelper.cs:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Security.Cryptography;

namespace AmazonProductAdvtApi
{
    class SignedRequestHelper
    ...
    ... some private consts and vars...

    public SignedRequestHelper(string awsAccessKeyId, string awsSecretKey, string destination)
    {
        this.endPoint = destination.ToLower();
        this.akid = awsAccessKeyId;
        this.secret = Encoding.UTF8.GetBytes(awsSecretKey);
        this.signer = new HMACSHA256(this.secret);
    }
A: 

"inaccessible due to its protection level" means you're trying to reference an item outside its intended scope, ie creating an instance of a private class from another unrelated class. the using statement doesn't appear to be the problem here.

lincolnk
+1  A: 

The class isn't marked public; therefore, it's inaccessible from other namespaces.

Most likely the other Amazon classes that use it are also in the AmazonProductAdvtApi namespace, so they don't have problems (a class with no explicit visibility gets internal by default).

If you want to use that class, change its declaration to public class SignedRequestHelper. Just be aware that the class may not be intended for public consumption, i.e. may lack certain types of error-checking that you'd normally expect in a public API.

Aaronaught
Ah, ok. I assumed Amazon would provide us with something we can just plug-and-play with.
Chris
I'm sure they did, but that doesn't necessarily mean that they want you to play with *everything* in the source. Clearly it's intended to be used by other classes in the `AmazonProductAdvtApi` namespace.
Aaronaught
Quite possibly so. I'm just going off of the sample code the provided. I'll keep researching I suppose.
Chris
+1  A: 

Perhaps this is not the public interface they want you to use. Maybe there is a public class that wraps this class.

JP Alioto
Perhaps. I wish the Amazon api docs were more clear on that.
Chris
? What makes you think it is a friend class? The friend keyword does not exist in C#.
Brian Genisio
@Brian: Quite right. Thank you.
JP Alioto