這可能是由於服務終結點綁定未使用 HTTP 協議造成的 原因數據量過大


今天又看到"這可能是由於服務終結點綁定未使用 HTTP 協議造成的"  這個蛋疼的錯誤  

這個錯誤之前也遇到過多次 歸納原因有

1、沒有重新生成代理文件

2、這是因為WCF返回值無法序列化造成的

但我今天遇到時 我想這次肯定不是這兩個原因之一  我想應該是數據量過大 於是把數據減少一部分后 一切正常 那就找解決方案 最后看到 這個帖子 http://topic.csdn.net/u/20080708/08/8158eac6-08fd-4e04-b37d-7dfc8137a6d9.html?seed=937996111&r=60490402#r_60490402  按文中的配置方法配置后 問題解決。

既然是好東西 那我就“偷”來  呵呵

 

解決方法:
用SvcConfigEditor為客戶端和服務端都加上一個behavior (服務端添加servicehehavior, 客戶端添加endpointbehavior),然后為這兩個服務各添加一個dataContractSerializer,把他的maxItemsInObjectGraph字段變成更大的數。

 

服務端配置:

<system.serviceModel>
     <diagnostics>
       <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
         logMessagesAtTransportLevel="true" />
     </diagnostics>
     <behaviors>
       <serviceBehaviors>
         <behavior name="NewBehavior">
           <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8000/ContactManager/md" />
           <serviceDebug includeExceptionDetailInFaults="true" />
           <dataContractSerializer maxItemsInObjectGraph="65536000" />        </behavior>
       </serviceBehaviors>
     </behaviors>
     <services>
       <service behaviorConfiguration="NewBehavior" name="WcfServiceLibrary1.ContactManager">
         <endpoint address="http://localhost:8000/ContactManager" binding="wsHttpBinding"
           bindingConfiguration="NewBindingStationCnfg" contract="WcfServiceLibrary1.IContactManager" />
         <endpoint address="http://localhost:8000/ContactManager/mex" binding="mexHttpBinding" contract="IMetadataExchange" />
       </service>
     </services>
     <bindings>
       <wsHttpBinding>
         <binding name="NewBindingStationCnfg" maxReceivedMessageSize="483647" />
       </wsHttpBinding>

     </bindings>
   </system.serviceModel>


客戶端的config:

     <system.serviceModel>
         <behaviors>
             <endpointBehaviors>
                <behavior name="NewBehavior">
                    <dataContractSerializer maxItemsInObjectGraph="6553600" />
                </behavior>
            </endpointBehaviors>
        </behaviors>
         <diagnostics>
             <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
                 logMessagesAtTransportLevel="true" />
         </diagnostics>
         <bindings>
             <wsHttpBinding>
                 <binding name="WSHttpBinding_IContactManager1" closeTimeout="00:01:00"
                     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                     bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                     maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                     messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                     allowCookies="false">
                     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                         maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                     <reliableSession ordered="true" inactivityTimeout="00:10:00"
                         enabled="false" />
                     <security mode="Message">
                         <transport clientCredentialType="Windows" proxyCredentialType="None"
                             realm="" />
                         <message clientCredentialType="Windows" negotiateServiceCredential="true"
                             algorithmSuite="Default" establishSecurityContext="true" />
                     </security>
                 </binding>
             </wsHttpBinding>
         </bindings>
         <client>
             <endpoint address="http://localhost:8000/ContactManager" behaviorConfiguration="NewBehavior"
                 binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IContactManager1"
                 contract="ServiceReference2.IContactManager" name="WSHttpBinding_IContactManager1">
                 <identity>
                     <userPrincipalName value="vblab1@redmond.corp.microsoft.com" />
                 </identity>
             </endpoint>
         </client>
     </system.serviceModel>

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM