对使用 WCF 服务感到困惑

本文关键字:服务 WCF | 更新日期: 2023-09-27 17:56:42

有一个WCF服务ServiceOne。它所做的只是实现一些函数,比如说int Add(int a, int b);

当我在另一个项目中使用此服务时:

ServiceOneClient client = new ServiceOneClient();
int result = client.Add(10,10);

它工作正常。

但是现在我必须创建另一个服务ServiceTwo,它只是实现了像这样的ServiceOne功能

int ServiceTwoAddMethod(int a, int b)
{
    return new ServiceOneClient().Add(a, b);
}

我认为一切都应该很好。但不知何故,当我在第三个项目中添加对 ServiceTwo 的引用时,此行代码

new ServiceTwoClient().Add(10, 10)

不返回我想看到的内容(20)。

请告诉我我做错了什么?

对使用 WCF 服务感到困惑

确保第三个项目具有对 Service2 的服务引用,但也具有对 Service1 和服务 2 的项目引用(假设它们都在同一解决方案中)

编辑:当我说服务1和服务2时,我当然是指每个服务的服务协定类库。 当然,我假设您有一个用于服务合同的项目和另一个用于实际服务实施的项目