繁体   English   中英

C#错误(使用接口方法):非静态字段,方法或属性需要对象引用

[英]C# error(using interface methods): An object reference is required for the non-static field, method, or property

我在使用文档过时的第三方API时遇到了问题,因此我试图弄清楚为什么这条@#$! 不起作用。 然后@@ $! 我的意思是“代码”,当然:)

据我所知,WAPISoap是我通过在Visual Studio中添加Web参考获得的公共界面。

我也知道Describe()方法接受两个参数,一个字符串和一个凭据类型的对象,它返回一个字符串。 任何帮助将不胜感激 :)

这是我到目前为止所得到的:

using WAPIClient;
using System;
using Project1.WsWWDAPI;
namespace WAPIClient
{
    class ResellerAPI
    {
        public void CallDescribe()
        {
            String sReturnXml;
            Credential m_Crededential = new Project1.WsWWDAPI.Credential();
            m_Crededential.Account = "account";
            m_Crededential.Password = "password";
            String sCLTRID = System.Guid.NewGuid().ToString();
            sReturnXml = WAPISoap.Describe(sCLTRID, m_Crededential);
            Console.WriteLine(sReturnXml);
        }
        static void Main(string[] args)
        {
            ResellerAPI reseller = new ResellerAPI();
            reseller.CallDescribe();
        }
    }
}

Describe方法不是静态的,这意味着您需要在WAPI类的实例上调用它:

WsWWDAPI.WAPI m_WAPIObj = null;
WsWWDAPI.Credential m_Crededential = null;

public void Init()
{
    m_WAPIObj = new WsWWDAPI.WAPI();
    m_Crededential = new WsWWDAPI.Credential();
    m_Crededential.Account  = "account";
    m_Crededential.Password = "password";
}
public void CallDescribe()
{
    String sReturnXml;
    String sCLTRID = System.Guid.NewGuid().ToString();
    sReturnXml = m_WAPIObj.Describe(sCLTRID, m_Crededential);
    Console.WriteLine( sReturnXml );
}
static void Main(string[] args)
{
    ResellerAPI reseller = new ResellerAPI();
    reseller.Init();
    reseller.CallDescribe();
}

请参阅: http//products.secureserver.net/guides/wsapiquickstart.pdf

该错误是因为您在静态上下文中使用了非静态方法-您应该具有WAPISoap的实例才能调用非静态的成员函数

听起来您需要创建WAPISoap实例,然后在该实例上调用Describe。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM