简体   繁体   English

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

[英]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 @#$! 我在使用文档过时的第三方API时遇到了问题,因此我试图弄清楚为什么这条@#$! 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. 据我所知,WAPISoap是我通过在Visual Studio中添加Web参考获得的公共界面。

I also know the Describe() method accepts two parameters, a string and an object of type credential and it returns a string. 我也知道Describe()方法接受两个参数,一个字符串和一个凭据类型的对象,它返回一个字符串。 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: 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();
}

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

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

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

暂无
暂无

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

相关问题 C#中出错:“非静态字段,方法或属性需要对象引用” - Error in C#: “An object reference is required for the non-static field, method, or property” C#修复错误:“非静态字段,方法或属性需要对象引用” - C# Fixing error: “An object reference is required for the non-static field, method, or property” C#错误:非静态字段,方法或属性需要对象引用 - C# error: An object reference is required for the non-static field, method, or property C#错误:非静态字段,方法或属性需要对象引用 - C# Error: Object reference is required for the non-static field, method, or property 为什么我在C#中得到“非静态字段,方法或属性需要对象引用”错误? - Why am I getting “object reference is required for the non-static field, method, or property” error in C#? C# 错误:“非静态字段、方法或属性需要对象引用” - C# error: "An object reference is required for the non-static field, method, or property" 错误:非静态字段,方法或属性需要对象引用 - Error: An object reference is required for the non-static field, method, or property 对象引用是必需的非静态字段,方法或属性错误 - An object reference is required non-static field, method, or property error 非静态字段,方法或属性错误需要对象引用 - An object reference is required for the non-static field, method or property error C#错误:非静态字段需要对象引用 - C# error : An object reference is required for the non-static field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM