[英]Error in C#: “An object reference is required for the non-static field, method, or property”
[英]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.