开发者

WFC + javascript MaxStringContentLength problem

开发者 https://www.devze.com 2022-12-19 00:40 出处:网络
I am accessing a WCF service using a JavaScript code <asp:ScriptManager ID=\"ScriptManager1\" runat=\"server\" EnablePartialRendering=\"true\">

I am accessing a WCF service using a JavaScript code

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

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

now the problem is when i pass a large chunk of string value, i am getting an exception

The InnerException message was 'There was an error deserializing the object of type System.String. The maximum string content length quota (8192) has been exceeded while reading XML data.

How do i set MaxStringContentLength value for this using JavaScript ?

Any advice ?

Thanks -Aruna


after few hours of googling i found out how to do this,

need to bind settings at the point of initialising the svc file.

create a custom class,

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

append .svc file header to

<%@ ServiceHost Factory="WebTV.DerivedFactory" 

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

. probably you will want to open this using a note pad, because VS editor goes straight to the codebehind file.

important part here is Factory="WebTV.DerivedFactory"

good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消