自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

正確設(shè)置實(shí)現(xiàn)WCF傳輸大數(shù)據(jù)技巧講解

開發(fā) 開發(fā)工具
WCF傳輸大數(shù)據(jù)往往都會出現(xiàn)一些錯(cuò)誤,導(dǎo)致傳輸失敗。如何正確的設(shè)置,來實(shí)現(xiàn)這一目的是一個(gè)開發(fā)人員必須要掌握的基礎(chǔ)技能。

WCF可以幫助我們用來傳輸數(shù)據(jù)。但是有沒有人遇到過需要大容量數(shù)據(jù)傳輸?shù)男枨竽??只要進(jìn)行正確的設(shè)置就可以實(shí)現(xiàn)WCF傳輸大數(shù)據(jù)。#t#

在從客戶端向WCF服務(wù)端傳送較大數(shù)據(jù)(>65535B)的時(shí)候,發(fā)現(xiàn)程序直接從Reference的BeginInvoke跳到EndInvoke,沒有進(jìn)入服務(wù)端的Service實(shí)際邏輯中,懷疑是由于數(shù)據(jù)過大超出限定導(dǎo)致的。

問題是我實(shí)際發(fā)送的數(shù)據(jù)是剛剛從WCF服務(wù)端接收過來的,一來一去,數(shù)據(jù)量差別并不大。

然后發(fā)現(xiàn),在客戶端和服務(wù)端實(shí)際使用的是不同的配置,對于客戶端,在添加ServiceReference時(shí)自動生成的ServiceReferences.ClientConfig文件中system.serviceModel節(jié)下有這樣的設(shè)置實(shí)現(xiàn)WCF傳輸大數(shù)據(jù):

 

  1. < bindings> 
  2. < basicHttpBinding> 
  3. < binding name="BasicHttpBinding_WcfService" 
    maxBufferSize="2147483647" 
  4. maxReceivedMessageSize="2147483647"> 
  5. < security mode="None" /> 
  6. < /binding> 
  7. < /basicHttpBinding> 
  8. < /bindings>然后在Client節(jié)里應(yīng)用Binding 
    Configuration:  
  9. < client> 
  10. < endpoint address="http://
    localhost:22000/Service/WcfService.svc"
     
  11. binding="basicHttpBinding" 
    bindingConfiguration="BasicHttpBinding_WcfService" 
  12. contract="WcfServiceReference.WcfService" 
    name="BasicHttpBinding_WcfService" />< /client> 

在Binding里指定了***緩存字節(jié)數(shù)和***接受字節(jié)數(shù),相當(dāng)于2G的大??!除非傳一整套連續(xù)劇,一般是夠用了。

而在服務(wù)端,Web.config文件里,Bindings節(jié)是空的,而Service也沒有指定bindingConfiguration屬性,那么它們采用的就是默認(rèn)的65535的大小。

問題找到,解決WCF傳輸大數(shù)據(jù)就比較容易了:

在Bindings節(jié)添加新的Binding設(shè)置,指定***接受數(shù)據(jù):

  1. < bindings> 
  2. < basicHttpBinding> 
  3. < binding name="LargeDataTransferServicesBinding"
     maxReceivedMessageSize="2147483647" 
  4. messageEncoding="Text" transferMode="Streamed"
     sendTimeout="00:10:00" /> 
  5. < /basicHttpBinding> 
  6. < /bindings>之后給相應(yīng)的Service
    指定bindingConfiguration屬性:
    < service behaviorConfiguration=
    "Server.Service.WcfServiceBehavior" 
  7. name="Server.Service.WcfService"> 
  8. < endpoint address="" binding=
    "basicHttpBinding" bindingConfiguration=
    "LargeDataTransferServicesBinding" 
    contract="Server.Service.WcfService" /> 
  9. < endpoint address="mex" binding=
    "mexHttpBinding" contract="IMetadataExchange" /> 
  10. < /service> 

這樣就可以從客戶端發(fā)送足夠大的數(shù)據(jù)了。

P.S.:

.net默認(rèn)只能傳4M的文件,所以盡管設(shè)定了Wcf兩端的配置,還是超不出.net的限定,所以如果要傳輸大文件,還需要在System.Web節(jié)下加上

< httpRuntimemaxRequestLength="102400" />
這里的單位是KB,這樣就可以傳100M的文件了,充分解決了WCF傳輸大數(shù)據(jù)的問題。當(dāng)然,這么大的文件,***還是分段傳輸比較好。

責(zé)任編輯:曹凱 來源: 博客園
相關(guān)推薦

2010-02-24 13:48:44

MSMQ使用WCF

2010-02-23 09:44:12

WCF dataCon

2010-02-22 16:26:47

WCF傳輸數(shù)據(jù)

2010-02-25 09:13:34

WCF異步調(diào)用

2009-12-22 15:33:50

WCF傳輸安全

2009-11-09 14:02:31

WCF傳輸數(shù)據(jù)

2010-02-22 16:19:25

WCF自托管

2009-12-22 19:14:36

WCF效率

2010-02-22 17:51:46

WCF傳較大數(shù)據(jù)

2009-12-21 14:49:27

2010-02-26 10:46:12

WCF行為擴(kuò)展

2010-02-24 10:35:56

WCF鏈接服務(wù)超時(shí)

2010-02-22 14:28:35

WCF實(shí)現(xiàn)loadin

2009-12-08 15:06:33

WCF傳輸DataSe

2010-02-23 17:49:56

WCF傳輸大數(shù)據(jù)

2009-11-09 09:23:10

WCF數(shù)據(jù)契約

2010-02-23 14:17:20

WCF配置文件

2010-02-26 13:40:28

WCF消息頭

2010-02-24 12:49:39

WCF枚舉

2010-02-26 17:44:51

WCF安全參數(shù)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號