新聞中心
用過(guò)WCF的朋友們應(yīng)該了解,在WCF中傳輸數(shù)據(jù)是一個(gè)比較簡(jiǎn)單的操作。那么在特定環(huán)境下,我們想要傳輸一個(gè)比較大的數(shù)據(jù)時(shí),又該如何正確操作呢?在這里我們將會(huì)針對(duì)WCF傳輸大數(shù)據(jù)這一問(wèn)題做一個(gè)詳細(xì)介紹。#t#

成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)的開發(fā),更需要了解用戶,從用戶角度來(lái)建設(shè)網(wǎng)站,獲得較好的用戶體驗(yàn)。創(chuàng)新互聯(lián)公司多年互聯(lián)網(wǎng)經(jīng)驗(yàn),見的多,溝通容易、能幫助客戶提出的運(yùn)營(yíng)建議。作為成都一家網(wǎng)絡(luò)公司,打造的就是網(wǎng)站建設(shè)產(chǎn)品直銷的概念。選擇創(chuàng)新互聯(lián)公司,不只是建站,我們把建站作為產(chǎn)品,不斷的更新、完善,讓每位來(lái)訪用戶感受到浩方產(chǎn)品的價(jià)值服務(wù)。
在從客戶端向WCF服務(wù)端傳送較大數(shù)據(jù)(>65535B)的時(shí)候,發(fā)現(xiàn)程序直接從Reference的BeginInvoke跳到EndInvoke,沒有進(jìn)入服務(wù)端的Service實(shí)際邏輯中,懷疑是由于數(shù)據(jù)過(guò)大超出限定導(dǎo)致的。
問(wèn)題是我實(shí)際發(fā)送的數(shù)據(jù)是剛剛從WCF服務(wù)端接收過(guò)來(lái)的,一來(lái)一去,數(shù)據(jù)量差別并不大。
然后發(fā)現(xiàn),在客戶端和服務(wù)端實(shí)際使用的是不同的配置,對(duì)于客戶端,在添加ServiceReference時(shí)自動(dòng)生成的ServiceReferences.ClientConfig文件中system.serviceModel節(jié)下有這樣的設(shè)置:
- < bindings>
- < basicHttpBinding>
- < binding name="BasicHttpBinding_WcfService" maxBufferSize="2147483647"
- maxReceivedMessageSize="2147483647">
- < security mode="None" />
- < /binding>
- < /basicHttpBinding>
- < /bindings>然后在Client節(jié)里應(yīng)用Binding Configuration:
- < client>
- < endpoint address="http://localhost:22000/Service/WcfService.svc"
- binding="basicHttpBinding" bindingConfiguration=
"BasicHttpBinding_WcfService"- contract="WcfServiceReference.WcfService"
name="BasicHttpBinding_WcfService" />< /client>
在Binding里指定了***緩存字節(jié)數(shù)和***接受字節(jié)數(shù),相當(dāng)于2G的大?。〕莻饕徽走B續(xù)劇,一般是夠用了。
而在服務(wù)端,Web.config文件里,Bindings節(jié)是空的,而Service也沒有指定bindingConfiguration屬性,那么它們采用的就是默認(rèn)的65535的大小。
問(wèn)題找到,解決WCF傳輸大數(shù)據(jù)就比較容易了:
在Bindings節(jié)添加新的Binding設(shè)置,指定***接受數(shù)據(jù):
- < bindings>
- < basicHttpBinding>
- < binding name="LargeDataTransferServicesBinding"
maxReceivedMessageSize="2147483647"- messageEncoding="Text" transferMode="Streamed"
sendTimeout="00:10:00" />- < /basicHttpBinding>
- < /bindings>
之后給相應(yīng)的Service指定bindingConfiguration屬性:
- < service behaviorConfiguration="Server.Service.WcfServiceBehavior"
- name="Server.Service.WcfService">
- < endpoint address="" binding="basicHttpBinding"
bindingConfiguration="LargeDataTransferServicesBinding"
contract="Server.Service.WcfService" />- < endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />- < /service>
這樣就能夠?qū)崿F(xiàn)WCF傳輸大數(shù)據(jù)了。
網(wǎng)頁(yè)名稱:WCF傳輸大數(shù)據(jù)相關(guān)問(wèn)題解決方案
網(wǎng)頁(yè)網(wǎng)址:http://fisionsoft.com.cn/article/cdeissd.html


咨詢
建站咨詢
