我正在使用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值?
有什么建议吗?
由于 -Aruna
答案 0 :(得分:0)
需要在初始化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#”Debug =“true” 服务= “WebTV.ForumService” CodeBehind =“ForumService.svc.cs”%&gt;
。可能你会想要用记事本打开它,因为VS编辑器直接进入代码隐藏文件。
这里重要的部分是Factory =“WebTV.DerivedFactory”
祝你好运!