日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WCF学习笔记一

發(fā)布時間:2025/3/15 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WCF学习笔记一 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

  在客戶端調用WCF服務時,引發(fā)以下異常:

“/”應用程序中的服務器錯誤。


已超過傳入消息(65536)的最大消息大小配額。若要增加配額,請使用相應綁定元素上的 MaxReceivedMessageSize 屬性。

說明:?執(zhí)行當前 Web 請求期間,出現(xiàn)未經(jīng)處理的異常。請檢查堆棧跟蹤信息,以了解有關該錯誤以及代碼中導致錯誤的出處的詳細信息。?

異常詳細信息:?System.ServiceModel.QuotaExceededException: 已超過傳入消息(65536)的最大消息大小配額。若要增加配額,請使用相應綁定元素上的 MaxReceivedMessageSize 屬性。

?

  根據(jù)異常提示可知,這是由于WCF在傳遞數(shù)據(jù)時超過了它默認的最大值,這個時候就需要我們手動配置它的信息傳遞最大值(65536),代碼如下:

?

<system.serviceModel><bindings><basicHttpBinding><binding name="BasicHttpBinding_SubjectContract" /><binding name="BasicHttpBinding_AreaContract" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" /><binding name="BasicHttpBinding_SearchConfigContract" /><binding name="BasicHttpBinding_YearContract" /></basicHttpBinding><wsHttpBinding><binding name="MetadataExchangeHttpBinding_SubjectContract"><security mode="None" /></binding><binding name="MetadataExchangeHttpBinding_AreaContract"><security mode="None" /></binding><binding name="MetadataExchangeHttpBinding_SearchConfigContract"><security mode="None" /></binding><binding name="MetadataExchangeHttpBinding_YearContract"><security mode="None" /></binding></wsHttpBinding></bindings><client><endpoint address="http://localhost:1234/AreaService.svc" binding="basicHttpBinding"bindingConfiguration="BasicHttpBinding_AreaContract" contract="AreaService.AreaContract"name="BasicHttpBinding_AreaContract" /><endpoint address="http://localhost:1234/SearchConfigService.svc"binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SearchConfigContract"contract="SearchConfigService.SearchConfigContract" name="BasicHttpBinding_SearchConfigContract" /><endpoint address="http://localhost:1234/SubjectService.svc"binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SubjectContract"contract="SubjectService.SubjectContract" name="BasicHttpBinding_SubjectContract" /><endpoint address="http://localhost:1234/YearService.svc" binding="basicHttpBinding"bindingConfiguration="BasicHttpBinding_YearContract" contract="YearService.YearContract"name="BasicHttpBinding_YearContract" /></client></system.serviceModel>

?

  找到對應服務的配置節(jié)點信息,添加紅色部分代碼即可。

?

代碼說明:

      maxBufferPoolSize:獲取或設置最大數(shù)量內存,在字節(jié),可用于消息緩沖區(qū)管理器的分配在終結點接收消息配置了此綁定。

                ?配置了此綁定的終結點所使用的緩沖池的最大大小(以字節(jié)為單位)。?默認值為 524288 個字節(jié)。?(簡單理解為從通道接收消息的最大緩存數(shù))

   maxReceivedMessageSize:獲取或設置最大大小,在字節(jié),在通道可接收配置了此綁定的消息。綁定可處理的最大消息大小(以字節(jié)為單位)。?默認值為 65,536 個字節(jié)。

                (簡單理解為最大接收的消息大小)?

?

  如果讀取的是XML數(shù)據(jù),則可能需要添加以下紅色部分代碼:

<wsHttpBinding><binding name="MetadataExchangeHttpBinding_SubjectContract"><security mode="None" /></binding><binding name="MetadataExchangeHttpBinding_AreaContract"> <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /><security mode="None" /></binding><binding name="MetadataExchangeHttpBinding_SearchConfigContract"><security mode="None" /></binding><binding name="MetadataExchangeHttpBinding_YearContract"><security mode="None" /></binding></wsHttpBinding>

?

代碼說明:    

    ReaderQuotas:獲取或設置可由配置了此綁定的終結點處理的 SOAP 消息的復雜性約束。(定義可由采用綁定配置的終結點處理的 SOAP 消息的復雜性約束)

            說明:復雜性約束包括多個項,例如最大元素深度和消息中字符串內容的最大長度等。?這些約束可以抵御某種類型的拒絕服務 (DoS) 攻擊,

               這些攻擊試圖利用消息復雜性來占用終結點處理資源。

    

<readerQuotas maxArrayLength="Integer"maxBytesPerRead="Integer"maxDepth="Integer"maxNameTableCharCount="Integer"maxStringContentLength=="Integer" />

?

特性

特性

說明

maxArrayLength

一個正整數(shù),指定 Windows Communication Foundation (WCF) 從客戶端接收的數(shù)據(jù)的最大允許數(shù)組長度。?默認值為 16384。

maxBytesPerRead

一個正整數(shù),指定每項讀取操作返回的字節(jié)的允許最大數(shù)。?默認值為 4096。(最大每次讀取長度)

maxDepth

一個正整數(shù),指定每項讀取操作的最大嵌套節(jié)點深度。?默認值為 32。(最大節(jié)點深度)

maxNameTableCharCount

一個正整數(shù),指定表名稱中允許的最大字符數(shù)。?默認值為 16384。(最大NameTableChar的數(shù)量)

maxStringContentLength

一個正整數(shù),指定 XML 元素內容中允許包含的最大字符數(shù)。?默認值為 8192。(最大內容長度)

?

      

  

?

?

?

?

?

?

注意點:

    1.這些屬性必須在客戶端和服務上設置。?一旦在服務配置文件中設置,這些值將不自動傳播到由 svcutil 工具或 Visual Studio 中的“添加服務引用”生成的客戶端配置文件。?

     ? 必須手動編輯生成的客戶端配置文件并設置適當?shù)闹怠?/span>

    2.復雜性約束可以抵御拒絕服務 (DOS) 攻擊,這些攻擊試圖利用消息復雜性來占用終結點處理資源。?其他復雜性約束包括多個項,

     ? 例如最大元素深度和消息中的字符串內容的最大長度。

    

Binding里的其它Max屬性的意思:

  maxBufferSize="65536" ? ? ?從通道接收消息的緩存大小.

  maxConnections="10" ? ? ? ?最大連接數(shù)目.

?

參考文檔:http://msdn.microsoft.com/zh-cn/library/system.servicemodel.wsdualhttpbinding.readerquotas(v=vs.110).aspx

     ??http://social.microsoft.com/Forums/zh-CN/73f31b97-bef5-47c6-b50e-d0d3140d8efb/wcf-bindingmax?forum=wcfzhchs

     ??http://msdn.microsoft.com/zh-cn/library/ms731325.aspx/html

     ??http://msdn.microsoft.com/zh-cn/beginner/ms731325(VS.90).aspx

     ??http://www.cnblogs.com/autumn/p/3502963.html

轉載于:https://www.cnblogs.com/52XF/p/3740304.html

總結

以上是生活随笔為你收集整理的WCF学习笔记一的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。