English 中文(简体)
WFC + JavaScript 的 MaxStringContentLength 问题
原标题:WFC + javascript MaxStringContentLength problem

我正在使用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>

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

内部接收信息是 类型系统标的脱轨有误。 努力。 在阅读XML数据时,最高限值(8192)已超出。

我如何使用JavaScript设置MaxStringContentLength值?

任何建议?

Thanks -Aruna

最佳回答

几个小时的谷歌搜索之后,我找到了如何做这件事的方法。

需要在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;
        } 
   }

页: 1

<%@ ServiceHost Factory="WebTV.DerivedFactory" 

Language="C#" Debug="true" Service="WebTV.ForumService" CodeBehind="ForumService.svc.cs" %>

可能您会想要使用记事本来打开这个文件,因为VS编辑器会直接进入代码后台文件。

这里的重要部分是 Factory="WebTV.DerivedFactory"。

祝你好运!

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签