2010-02-05 21 views
0

我訪問使用JavaScript代碼WFC + JavaScript的MaxStringContentLength問題

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"> 
    <Services> 
     <asp:ServiceReference Path="ForumService.svc" /> 
    </Services> 
</asp:ScriptManager> 

在web.config中

<system.serviceModel> 
    <diagnostics> 
     <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" /> 
    </diagnostics> 
    <serviceHostingEnvironment /> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSHttpBinding_ITranscriptService" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/> 
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/> 
      <security mode="Message"> 
      <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/> 
      <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true"/> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:10780/TranscriptService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ITranscriptService" contract="TVServiceReference.ITranscriptService" name="WSHttpBinding_ITranscriptService"> 
     <identity> 
      <dns value="localhost"/> 
     </identity> 
     </endpoint> 
    </client> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name="WebTV.ForumServiceAspNetAjaxBehavior"> 
      <enableWebScript /> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name="WebTV.TranscriptServiceBehavior" > 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="true"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service behaviorConfiguration="WebTV.TranscriptServiceBehavior" 
     name="WebTV.TranscriptService"> 
     <endpoint address="" binding="wsHttpBinding" contract="WebTV.ITranscriptService"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     </service> 
     <service behaviorConfiguration="WebTV.TranscriptServiceBehavior" name="WebTV.ForumService"> 
     <endpoint address="" behaviorConfiguration="WebTV.ForumServiceAspNetAjaxBehavior" 
      binding="webHttpBinding" contract="WebTV.ForumService" /> 
     </service> 
    </services> 
    </system.serviceModel> 

現在的問題是,當我經過一大塊字符串值的WCF服務,我收到異常

設置InnerException消息是「有反序列化System.String類型的對象錯誤。讀取XML數據時,超過了最大字符串內容長度限額(8192)。

如何設置MaxStringContentLength值這個使用JavaScript?

有什麼建議嗎?

感謝 -Aruna

回答

0

google搜索,我發現瞭如何做到這一點的幾個小時後,

需要在初始化SVC文件的點綁定設置。

創建自定義類,

public class DerivedFactory : ServiceHostFactory 
    { 
     protected override ServiceHost CreateServiceHost 
            (Type t, Uri[] baseAddresses) 
     { 
     ServiceHost host = base.CreateServiceHost(t, baseAddresses); 
     WebHttpBinding binding = new WebHttpBinding(); 
     binding.Security.Mode = WebHttpSecurityMode.None; 
     binding.Security.Transport.ClientCredentialType 
            = HttpClientCredentialType.None; 
     binding.MaxReceivedMessageSize = Int32.MaxValue; 
     binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue; 
     binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue; 
     host.Description.Endpoints[0].Binding = binding; 
     return host; 
     } 
    } 

追加.svc文件頭到

<%@ ServiceHost Factory="WebTV.DerivedFactory" 

語言= 「C#」 調試= 「真」 服務= 「WebTV.ForumService」 CodeBehind =「ForumService.svc.cs」%>

。可能你會想用記事本打開它,因爲VS編輯器會直接進入代碼隱藏文件。這裏

重要組成部分,是工廠= 「WebTV.DerivedFactory」

好運!