随笔 - 229  文章 - 2  评论 - 511  阅读 - 84万

WCF异常收集


   1  调用Subscribe时引发异常:
      客户端代码如下:
       TempChangedHandler handler = new TempChangedHandler();

            InstanceContext siteTempChangedHandler = new InstanceContext(null,handler);
            TempChangedPubProxy proxyTempChanged = new TempChangedPubProxy(siteTempChangedHandler);
            proxyTempChanged.Subscribe();

            Console.WriteLine("Client is running....press any key to terminate.");
            proxyTempChanged.Unsubscribe();
           proxyTempChanged.Subscribe();//这时调用该代码回引发异常.

       异常信息如下:Unhandled Exception: System.InvalidOperationException: This channel cannot send any more messages because IsTerminating operation 'Unsubscribe' has already been
 called.
       解决方法:因为管道已经关闭,所以需要重新开启管道即可:
proxyTempChanged = new TempChangedPubProxy(siteTempChangedHandler);//再次实力化客户端代理类即可

    2  当使用ServiceHost类的第一种重载实力化时:public ServiceHost(object singletonInstance, params Uri[] baseAddresses):
       如果第一个参数的类没有添加如下代码[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]标记
      则在调用ServiceHost.Open()方法时回抛出异常:
Unhandled Exception: System.InvalidOperationException: In order to use one of th
e ServiceHost constructors that takes a service instance, the InstanceContextMod
e of the service must be set to InstanceContextMode.Single.  This can be configu
red via the ServiceBehaviorAttribute.  Otherwise, please consider using the Serv
iceHost constructors that take a Type argument.

   3  [OperationContract(IsOneWay = true)]
     当IsOneWay设置为true时,被修饰的函数必须时void类型,否则在调用该函数时会抛出异常:
     
     
posted on   stswordman  阅读(730)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
< 2007年3月 >
25 26 27 28 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
1 2 3 4 5 6 7

点击右上角即可分享
微信分享提示