|
近日在使用wcf的restfull架構(gòu)服務(wù)時(shí)遭遇到了提交大數(shù)據(jù)的問題。
大數(shù)據(jù)包含兩種情形: 1)單條數(shù)據(jù)量過大。 2)提交或獲取的數(shù)據(jù)條數(shù)過多。 在測試時(shí)發(fā)現(xiàn),默認(rèn)設(shè)置下當(dāng)單條JSON數(shù)據(jù)大于30K時(shí)服務(wù)便不予受理。 提交或獲取數(shù)據(jù)大小的限制來自兩方面,即IIS服務(wù)和WCF服務(wù)。 這兩方面的限制都可以通過配置WCF服務(wù)端的Web.config相關(guān)配置節(jié)點(diǎn)的方式解決。 廢話不說了,直接上解決方案。
<?xml version="1.0" encoding="utf-8"?> <configuration> <connectionStrings> <add name="BaseConnectionString" connectionString="server=.\SQLEXPRESS;database=TLPBizF;uid=*******;pwd==*******;" providerName="System.Data.SqlClient" /> <add name="BizDBConnectionString" connectionString="server=.\SQLEXPRESS;database=TLPBizDB;uid==******;pwd==*******;" providerName="System.Data.SqlClient" /> </connectionStrings> <appSettings> <add key="TimeOutMinutes" value="20" /> <add key="BizDBName" value="TLPBizDB"/> <add key="aspnet:MaxJsonDeserializerMembers" value="1500000000" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> <handlers accessPolicy="Read, Execute, Script" /> <staticContent> <mimeMap fileExtension=".svc" mimeType="application/octet-stream" /> </staticContent> </system.webServer> </configuration>
<?xml version="1.0" encoding="utf-8"?> <configuration> <connectionStrings> <add name="BaseConnectionString" connectionString="server=.\SQLEXPRESS;database=TLPBizF;uid=*******;pwd==*******;" providerName="System.Data.SqlClient" /> <add name="BizDBConnectionString" connectionString="server=.\SQLEXPRESS;database=TLPBizDB;uid==*******;;pwd==*******;" providerName="System.Data.SqlClient" /> </connectionStrings> <appSettings> <add key="TimeOutMinutes" value="20" /> <add key="BizDBName" value="TLPBizDB"/> <add key="aspnet:MaxJsonDeserializerMembers" value="1500000000" /> </appSettings> <system.web> <compilation debug="true" targetFramework="4.0" /> <httpRuntime maxRequestLength="2147483644"/> </system.web> <system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength="2147483644"/> </webServices> </scripting> </system.web.extensions> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> <behavior name="BigDataServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> <standardEndpoints> <webHttpEndpoint> <!-- 服務(wù)節(jié)點(diǎn)配置 --> <standardEndpoint name="BigDataServiceEndPoint" transferMode="Buffered" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" defaultOutgoingResponseFormat="Json" helpEnabled="true" automaticFormatSelectionEnabled="true"> <readerQuotas maxDepth="64" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxArrayLength="2147483647" ></readerQuotas> </standardEndpoint> </webHttpEndpoint> </standardEndpoints> <services> <!-- 服務(wù)對應(yīng)配置 --> <service name="SFiresoft.TLP.Services.BizCoreService" behaviorConfiguration="BigDataServiceBehavior"> <endpoint endpointConfiguration="BigDataServiceEndPoint" kind="webHttpEndpoint" contract="SFiresoft.TLP.Services.IBizCoreService" > </endpoint> </service> </services> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true" /> <handlers accessPolicy="Read, Execute, Script" /> <staticContent> <mimeMap fileExtension=".svc" mimeType="application/octet-stream" /> </staticContent> </system.webServer> </configuration> 對比: 1)system.web節(jié)點(diǎn): <httpRuntime maxRequestLength="2147483644"/> 應(yīng)對IIS服務(wù)請求數(shù)據(jù)大小限制的設(shè)置。 2)system.serviceModel節(jié)點(diǎn)下“webHttpEndpoint”的配置: <standardEndpoint name="MyPoint" transferMode="Buffered" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" defaultOutgoingResponseFormat="Json" helpEnabled="false" automaticFormatSelectionEnabled="true"> <readerQuotas maxDepth="64" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxArrayLength="2147483647" ></readerQuotas> </standardEndpoint> 此處:
如服務(wù)地址:http://localhost:9900/MapService.svc 查看服務(wù)方式:http://localhost:9900/MapService.svc/help 如下圖: 3)system.serviceModel節(jié)點(diǎn)下“service”的配置: <services> <service name="SFiresoft.TLP.Services.BizCoreService" behaviorConfiguration="Wcf4BigData.Web.BigDataServiceBehavior"> <endpoint endpointConfiguration="MyPoint" kind="webHttpEndpoint" contract="SFiresoft.TLP.Services.IBizCoreService"> </endpoint> </service> </services>
|
|
|