C#“使用”我这样做对吗? (由于防护等级无法访问)
http://www.dscredstorm.com/getisbninfo.aspx
我正在尝试使用 Amazon API。我下载了他们的示例代码,这是一个 C# Windows 窗体应用程序,但我认为它也应该适用于 C# 网站,对吗?
SignedRequestHelper.cs 是一个似乎具有一些我需要发送签名请求的功能的文件。它的命名空间是 AmazonProductAdvtApi。我将该文件放入 App_Code/Csharp 中,并添加了“using AmazonProductAdvtApi;”到我的页面。
但我收到此错误:“AmazonProductAdvtApi.SignedRequestHelper”由于其保护级别而无法访问
为什么?
更多信息: SignedRequestHelper helper = new SignedRequestHelper(accessKeyId,secretKey,目的地);
请参阅: http://www.dscredstorm.com/getisbninfo.aspx
这是类声明对于 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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该类未标记为公开;因此,无法从其他命名空间访问它。
使用它的其他 Amazon 类很可能也在
AmazonProductAdvtApi
命名空间中,因此它们不会出现问题(没有显式可见性的类默认获取internal
)。如果您想使用该类,请将其声明更改为
public class SignedRequestHelper
。请注意,该类可能不适合公共使用,即可能缺乏您通常在公共 API 中期望的某些类型的错误检查。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 getsinternal
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.也许这不是他们希望您使用的公共界面。也许有一个公共类来包装这个类。
Perhaps this is not the public interface they want you to use. Maybe there is a public class that wraps this class.
“由于其保护级别而无法访问”意味着您试图引用其预期范围之外的项目,即从另一个不相关的类创建私有类的实例。 using 语句似乎不是这里的问题。
"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.