2013-02-11 62 views
0

我的ASP.NET服務器提供了一組由我的WPF客戶端使用的WCF服務。一切都很好,直到字符串字段的長度超過8K。這現在在ASP.NET服務器上產生以下異常...ASP.NET託管WCF服務,需要增加MaxStringContentLength,但如何?

反序列化Project.ModelType類型的對象時出現錯誤。 已經超過最大字符串內容長度配額(8192),而 讀取XML數據。此配額可以通過改變在XmlDictionaryReaderQuotas創建XML讀取器時 對象使用的 MaxStringContentLength屬性增加。

我已在MaxStringContentLength的增加值要對WPF的app.config 64K但這並沒有解決這個問題。所以我想我需要在ASP.NET端增加這個值。但是我沒有web.config中的任何值來更改!這裏是我的web.config顯示此...

<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 

    <authentication mode="Forms"> 
     <forms name=".ASPXFTOAUTH" 
      timeout="10" 
      slidingExpiration="true" 
      cookieless="UseCookies"/> 
    </authentication> 

    <membership> 
     <providers> 
     <clear/> 
     </providers> 
    </membership> 

    <customErrors defaultRedirect="~/Error.htm" mode="RemoteOnly"> 
     <error statusCode="404" redirect="~/404.aspx" /> 
    </customErrors> 
    </system.web> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

    <system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" 
           multipleSiteBindingsEnabled="true" /> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

那麼,如何更新服務器,以指示較高MaxStringContentLength價值?我的服務app.config看起來像這樣...

<system.serviceModel> 
    <bindings> 
    <basicHttpBinding> 
     <binding name="BasicHttpBinding_IAccess" closeTimeout="00:01:00" 
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
       allowCookies="false" bypassProxyOnLocal="false" 
       hostNameComparisonMode="StrongWildcard" 
       maxBufferSize="131072" maxBufferPoolSize="524288" maxReceivedMessageSize="131072" 
       messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" 
       useDefaultWebProxy="true"> 
     <readerQuotas maxDepth="32" maxStringContentLength="65536" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     <security mode="None"> 
      <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
      <message clientCredentialType="UserName" algorithmSuite="Default" /> 
     </security> 
     </binding> 
    </basicHttpBinding> 
    </bindings> 

    <client> 
    <endpoint binding="basicHttpBinding" 
       bindingConfiguration="BasicHttpBinding_IAccess" 
       contract="AccessService.IAccess" 
       name="BasicHttpBinding_IAccess" /> 
    </client> 
</system.serviceModel> 

任何想法?

UPDATE:

我的服務是由具有類的Access.svc「

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public class Access : IAccess 
{ 
    // ...IAccess method implementations 
} 

...它具有以下標記定義...

<%@ ServiceHost Language="C#" Debug="true" 
       Service="Ecotech.AMS.WebServer.Access" 
       CodeBehind="Access.svc.cs" %> 

正如在評論中指出的那樣,web.config中沒有任何關於該服務的具體內容。

+0

你必須失去了一些東西。該_can't_不是你的整個web.config文件。你沒有提及那裏的服務。你是如何添加ServiceReference的? – 2013-02-11 23:59:05

+0

不確定,所以我不會將其作爲答案發布,但唯一值在8K限制之下的是'maxBytesPerRead'。 MSDN指出「一個正整數,它指定每次讀取返回的最大允許字節數。默認值是4096.'嘗試增加此值 – Steve 2013-02-12 00:00:45

+0

@Steve,他需要在客戶端設置這個值作爲很好,但配置文件甚至沒有對服務的引用。 – 2013-02-12 00:04:11

回答

0

嘗試點擊「添加服務引用」通過項目的右鍵菜單。這樣做會將必要的配置信息添加到您的web.config文件中。

一旦你做到這一點,你可以在你的綁定設置maxReceivedMessageSize屬性。這樣做會最準確地反映你在WCF服務方面所做的事情。

+0

右鍵點擊我的WPF項目給出了「添加服務引用」選項,但右鍵單擊ASP.NET項目沒有。請注意,ASP.NET是託管服務的地方,所以我不認爲將自己的服務引用添加到工作中。 – 2013-02-12 02:12:04

0

,你需要工作的地方是web配置,你需要添加的服務行爲,您可以設置數據的大小。例如像這樣,

<behaviors> 
     <serviceBehaviors> 
     <behavior name="SilverlightWCFLargeDataApplication"> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
     </behavior> 

     </serviceBehaviors> 
     <endpointBehaviors> 
     <behavior name="SilverlightWCFLargeDataApplication"> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 

如果不工作,發佈您的web配置here.Hope它幫助。