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

发布于 2025-01-06 13:15:58 字数 525 浏览 3 评论 0原文

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

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

它无法将实现 (IServiceCallback) 作为 ServiceContract 的类型 (ServiceCallback) 的代理强制转换为 ICommunicationObject 类型,它返回 null

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

异常:

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

I trying to disconnect client to server:

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

It can't be casting proxy of type (ServiceCallback) that implements (IServiceCallback) as ServiceContract to type ICommunicationObject , it returns null

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

Exception:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怂人 2025-01-13 13:15:58

您的 ServiceCallback 类需要实现 System.ServiceModel.ICommunicationObject
如果没有,就像你的情况一样,铸造将会失败。

Your ServiceCallback class needs to implement System.ServiceModel.ICommunicationObject
If it doesn't, like in your case, the casting will fail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文