c# - WCF Service Reference.cs 方法给出错误:非静态字段、方法或属性需要对象引用
问题描述
我多次看到这个问题并且明白我需要在原始方法声明中添加静态。问题是这不是我控制的方法。在我的 C# 代码中,我添加了一个服务参考。它是 SOAP (XML) API。这不是我的 API。编译器错误出现在我在程序中调用的 Reference.cs 中的 WCF void 方法上。
程序.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Console.ThirdPartyService;
namespace Console
{
class Program
{
static void Main(string[] args)
{
// New Third Party Service Client
ThirdPartyServiceClient client = new ThirdPartyServiceClient();
// Set user email address
// Method is type void.
// Compiler generates object reference error for non-static method.
client.SetEMail("test@example.com");
}
}
}
参考.cs
...
public void SetEmail(string email) {
base.Channel.SaveUserInfo(email);
}
...
假设服务提供商不会更新他们的 API 来解析,如果这是解决方案的话。我还能如何解决这个问题?
解决方案
推荐阅读
- python - 崇高的构建系统错误“在''中找不到'__main__'模块”
- java - Java流中无与伦比的类型捕获和int allMatch()
- javascript - 使用 Apps 脚本抓取 javascript 呈现的网页
- javascript - Javascript 将字符串拆分为数组字典(键 -> 值)(正则表达式)
- java - JPanel 中 getGraphics() 中的 NullPointer
- sql - 如何使用 SQL(在 Oracle 数据库中)从具有逗号分隔值字段的单个记录创建新记录
- java - Spring session 和 cookies 是否仍然相关,因为有 spring security 和 JWT
- c - nslooup.c 不能处理http/https?
- apache-spark - Apache Spark 与 MapReduce
- powershell - 当我尝试在 Azure Run 书籍中导入 AzureRM 模块时,“确定”按钮未启用