zoukankan      html  css  js  c++  java
  • WCF基本知识

    1.开通WCF调试服务:

             须在服务端的行为中作如下配置:includeExceptionDetailInFaults="true" 代码如下:

                   <behaviors>

                       <serviceBehaviors>

                             <behavior name="MyBehavior">

                                  <serviceDebug  includeExceptionDetailInFaults="true" ></serviceDebug>

                              </behavior>

                       </serviceBehaviors>

                    </behaviors>

    2.关于WCF客户端信道异常的处理方法,须在catch中新建,且体代码如下:

                ChannelFactory<IContract> factory=new ChannelFactory<IContract>("myclient");

                IContract proxy=factory.CreateChannel();

                try

                 {

                         proxy.GoFunction();

                 }

                 catch(Exception ex)

                  {

                          if(proxy.InnerChannel.State == CommunicationState.Faulted)

                           {

                                      factory=new ChannelFactory<IContract>("myclient");

                                      // proxy=factory.CreateChannel();

                           }

                  }

    3.当WCf服务出现TimeOutException或CommunicationException时,当前信道壮态变成Faulted,表示信道出现错误,

       将使信道不能用于后续通信,即使调用close方法关闭也不行,此时客户端须调用Abort方法强制中断该信道。

         using(ChannelFactory<IContract>  factory=new ChannelFactory<IContract>("MyClient"))

         {

                 IContract  proxy=factory.CreateChannle();

                 try

                 {

                         proxy.GoFunction();

                         (proxy as ICommunicationObject).Close();  // 这里是关闭信道

                  }

                  catch(CommunicationException ex)

                  {

                          (proxy as ICommunicationObject).Abort();    // 强制杀死信道

                   }

                   catch(TimeoutException ex)

                    {

                            (proxy as ICommunicationObject).Abort();    // 强行释放信道

                     }

                     catch(Exception ex)

                    {

                             LogError.Message(ex.Message);

                    }

         }

               

               

                 

  • 相关阅读:
    质量属性的六个常见属性场景——以《淘宝网》为例
    软件架构师如何工作——架构漫谈读后感
    机器学习——决策树
    使用八股搭建手写数据集神经网络
    大三寒假学习进度笔记(三十)
    大三寒假学习进度笔记(二十九)
    大三寒假学习进度笔记(二十八)
    大三寒假学习进度笔记(二十七)—— 强化学习
    含e最多的单词
    数据挖掘复习1
  • 原文地址:https://www.cnblogs.com/yingger/p/3755980.html
Copyright © 2011-2022 走看看