【发布时间】:2015-04-28 03:09:15
【问题描述】:
我已经查看了很多关于我遇到的问题的示例(包括Passing Interface in a WCF Service?),但直到现在还没有找到解决方案。我有一个 Wcf 服务库 (.NET 4.0),其中包含以下内容
public class Service : IService
{
public bool Ping(IChannelManager channelManager)
{
return channelManager.Ping();
}
}
[ServiceContract]
public interface IService
{
[OperationContract]
bool Ping(IChannelManager channelManager);
}
[ServiceContract]
[ServiceKnownType(typeof(TestChannelName))]
public interface IChannelManager
{
[OperationContract]
bool Ping();
}
[DataContract]
public class TestChannelName : IChannelManager
{
public bool Ping()
{
//perform a ping
return true;
}
}
我的项目编译良好。但是当我尝试从控制台应用程序将其添加为服务参考时,我可以很好地添加它并尝试访问如下方法;
using (Test.ServiceClient oClient = new Test.ServiceClient())
{
oClient.Ping();
}
但我遇到的问题是 Wcf 服务上的 Ping() 方法,接口类型是对象 channelmanager 吗?喜欢
我尝试将 [ServiceKnownType(typeof(TestChannelName ))] 添加到两个接口,但没有成功。
我哪里错了?
【问题讨论】:
-
看起来你想要一个神奇的IChannelManager服务契约的服务实现?或者我读错了问题。谁创建了一个 TestChannel 实例并调用了 IService 实现?
-
Service : IService 是我的 Wcf 服务。我有一个我希望能够调用的方法 Ping(),它将根据我通过的 IChannelManager 执行不同的 Ping 测试
-
你能修复你的客户端示例来显示这个吗?
-
我更新了我的问题以显示正在显示的对象类型
-
我猜客户来自 mex 还是 wsdl?