• 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);

                    }

         }

               

               

                 

  • 相关阅读:
    中文字体
    URL锚点HTML定位技术机制
    关于JS异步加载方案
    select标签用法
    javascript refresh page 几种页面刷新的方法
    用JavaScript刷新框架子页面的七种方法
    robots.txt用法
    netstat 基本用法
    linux下ps命令
    socket编程和并发服务器
  • 原文地址:https://www.cnblogs.com/yingger/p/3755980.html
Copyright © 2020-2023  润新知