简体   繁体   中英

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

I'm having trouble using a third party API that has outdated documentation, so I'm trying to figure out why this piece of @#$! isn't working. And by @#$! i mean "code", of course :)

So as far as i know WAPISoap is a public interface that I have obtained by adding a web reference in visual studio.

I also know the Describe() method accepts two parameters, a string and an object of type credential and it returns a string. Any help would be greatly appreciated :)

Here's what i got so far:

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();
        }
    }
}

The Describe method is not static, which means you need to call it on an instance of the WAPI class:

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();
}

See: http://products.secureserver.net/guides/wsapiquickstart.pdf

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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