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 2007-03-02 11:01  stswordman  阅读(728)  评论(0编辑  收藏  举报