zoukankan      html  css  js  c++  java
  • 调用WCF出现的异常

    使用如下代码调用调用远程服务时,
                       try
                        {
                            using (GetSimServiceReference.GetSimServiceClient client = new GetSimServiceReference.GetSimServiceClient())
                            {
                                client.computerSim(DepartmentNo, FileID, F_intput.Length, ReadStringArrayFromStrings());
                            }
                        }
                        catch (CommunicationObjectFaultedException cofe)
                        {
                            ShowException.SaveLogAsTXTInfoex("调用WCF服务失败,异常信息:" + cofe.Message);
                        }
                        catch (Exception ex)
                        {
                            ShowException.SaveLogAsTXTInfoex("调用WCF服务失败,异常信息:" + ex.Message+f_intput.FullName);
                        }

    出现如下异常提示:
    通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为其处于“出错”状态
    并被CommunicationObjectFaultedException捕获到。在MSDN查找,由于关闭client时出现异常会导致CommunicationObjectFaultedException抛出。

    这是由于使用了using 关键字,在离开using的作用域时,会调用dispose方法来释放资源,在强制关闭cilent时,抛出了CommunicationObjectFaultedException异常。这是由于使用了using关键字来清理资源,在清理资源时导致异常,把using关键字移除,更能直接找到导致异常的原因。在移除using之后,系统抛出了如下异常:
    The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:fileStrings. The InnerException message was 'There was an error deserializing the object of type System.Collections.Generic.IEnumerable`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.'.  Please see InnerException for more details。
    到这里异常已经很明显了,传输的数据超出了WCF最大允许的长度。这个错误本来应该很容易被修正,但是因为使用Using,导致不能找到出错的正确位置,而花费了相当多的时间。的如下配置(红色字体),异常就没有发生了:
                     <bindings>
       <netTcpBinding>
        <binding name="GetSimService" closeTimeout="00:10:00" openTimeout="00:10:00"
                        receiveTimeout="00:10:00" sendTimeout="00:10:00" transactionFlow="false"
                        transferMode="Buffered" transactionProtocol="OleTransactions"
                        hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                        maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="100"
                        maxReceivedMessageSize="2147483647">
         <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
         <reliableSession ordered="true" inactivityTimeout="00:10:00"
                            enabled="false" />
         <security mode="Transport">
          <transport clientCredentialType="Windows" protectionLevel="EncryptA

    ndSign" />
          <message clientCredentialType="Windows" />
         </security>
        </binding>
       </netTcpBinding>
      </bindings>

  • 相关阅读:
    py2exe
    Microsoft Visual C++ Compiler for Python 2.7
    BeautifulSoup-find,findAll
    用vc生成可被python调用的dll文件
    xp下安装jdk8
    jython安装
    java java.lang.NoClassDefFoundError 的解决办法
    Python聊天室
    我的IOT入门课程上线了。
    Mybatis的CRUD操作
  • 原文地址:https://www.cnblogs.com/goxmpx/p/3314290.html
Copyright © 2011-2022 走看看