gpt4 book ai didi

c# - 无法通过类库使用 WCF 服务客户端

转载 作者:行者123 更新时间:2023-11-30 20:45:14 25 4
gpt4 key购买 nike

我在 http://localhost:20999/WCFService 上创建了一个简单的 WCF 服务

我可以创建一个客户端来使用控制台应用程序调用 Web 服务方法,但是在类库中创建 WCF 客户端时出现错误。

Could not find default endpoint element that references contract ...

  • VS2010
  • 测试客户端在 x64 中编译

然后我创建了一个简单的测试应用程序,其中包含 ConsoleApp 和 ClassLib。这两个项目都将 WCF 服务添加为服务引用。

Client solution

类 1 包含测试函数

public void Test()
{
ServiceReference2.TSI7WCFServiceClient client = new ServiceReference2.TSI7WCFServiceClient();
Console.WriteLine(client.Invoke("123", "456"));
}

和 ConsoleApp Program.cs

    Console.WriteLine("---- Call WCF directly ----");
ServiceReference1.TSI7WCFServiceClient client = new ServiceReference1.TSI7WCFServiceClient();
String result = client.Invoke("Test", "This is Parameter");
Console.WriteLine("Result = {0}", result);
client.Close();

Console.WriteLine("\n\n---- Call WCF via ClassLib ----");
ClassLibrary1.Class1 clientLib = new ClassLibrary1.Class1();
clientLib.Test();

这是结果 Console result

最佳答案

确保将端点信息从类项目的 app.config 复制到控制台项目的 app.config。

关于c# - 无法通过类库使用 WCF 服务客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28446059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com