码迷,mamicode.com
首页 > 其他好文 > 详细

WCF基本知识

时间:2014-06-07 03:55:11      阅读:316      评论:0      收藏:0      [点我收藏+]

标签:c   style   a   color   com   cti   

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

                }

     }

           

           

             

WCF基本知识,布布扣,bubuko.com

WCF基本知识

标签:c   style   a   color   com   cti   

原文地址:http://www.cnblogs.com/yingger/p/3755980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!