WCF之传递较长字符串(参数)
最近在做一个WCF端生成word的功能,在Silverlight端调用WCF传递一系列参数之后,发现会出现错误。经过多次测试是因为我传递了图片的byte[]过去,结果导致参数长度超出了限制,就over了。又经过了多方资料的查询,最终得到了解决方案,主要是对web.config进行正确的配置,代码如下:
<system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="FileServiceBehavior"> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> <dataContractSerializer maxItemsInObjectGraph="2147483647"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> <services> <service behaviorConfiguration="FileServiceBehavior" name="RichTextBoxDemo.Web.FileService"> <endpoint address="" bindingConfiguration="basicHttpBinding_Generic" binding="basicHttpBinding" contract="RichTextBoxDemo.Web.IFileService"/> </service> </services> <bindings> <basicHttpBinding> <binding name="basicHttpBinding_Generic" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/> <security mode="None"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> </bindings> </system.serviceModel>
注意 长度为 "2147483647"的地方就是要注意和修改的地方,好了,再次打开你的程序传递较长的字符串(其他类型)会神奇的发现,没有出现NonFound错误。