代码之家  ›  专栏  ›  技术社区  ›  kakopappa

wfc+javascript maxStringContentLength问题

  •  0
  • kakopappa  · 技术社区  · 15 年前

    我正在使用javascript代码访问WCF服务

    <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>
    

    现在的问题是,当我传递一大块字符串值时,我得到一个异常

    InnerException消息为“反序列化System.String类型的对象时出错。”读取XML数据时超过了最大字符串内容长度配额(8192)。

    如何使用javascript为此设置maxStringContentLength值?

    有什么建议吗?

    谢谢 -阿鲁纳

    1 回复  |  直到 14 年前
        1
  •  0
  •   Aran Mulholland JohnnyAce    14 年前

    经过几个小时的谷歌搜索,我发现了如何做到这一点,

    需要在初始化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" 
    

    language=“c”debug=“真” service=“webtv.forumService” codebehind=“forumservice.svc.cs”%>

    . 也许你会想用记事本打开它,因为vs编辑器直接转到codebehind文件。

    这里的重要部分是factory=“webtv.derivedFactory”

    祝你好运!