无法将Callback对象强制转换为System.ServiceModel.ICommunicationObject类型

时间:2012-02-18 22:46:59

标签: c# wcf wcf-client

我尝试断开客户端与服务器的连接:

if (((ICommunicationObject)proxy).State == CommunicationState.Opened)
{
   proxy.DisConnect();
}

它不能将实现(IServiceCallback)的类型(ServiceCallback)的代理转换为ServiceContract来键入ICommunicationObject,它返回null

 public class ServiceCallback : IServiceCallback , IDisposable { /* Implementation */ }

例外:

Unable to cast object of type 'Partition.ServiceCallback' to type 'System.ServiceModel.ICommunicationObject'.

1 个答案:

答案 0 :(得分:1)

您的ServiceCallback课程需要实施System.ServiceModel.ICommunicationObject 如果没有,就像在你的情况下,铸造会失败。