今天早上我遇到了一个问题,即返回一个文本字符串作为Web Service调用的结果.我得到的错误是在下面
************** Exception Text **************
System.ServiceModel.CommunicationException: Error in deserializing body of reply message for operation 'GetFilingTreeXML'. ---> System.InvalidOperationException: There is an error in XML document (1, 9201). ---> System.Xml.XmlException: The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 9201.
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at …
Run Code Online (Sandbox Code Playgroud) 我需要将maxStringContentLength更改为大于8192的值但尚未成功执行此操作.如果收到的数据量大于8192字节,我的WCF服务将生成异常.我已经用尽了我的搜索,似乎没有任何帮助.我应该指出异常来自服务器.忘记客户端,因为我看到直接从服务器上的WCF生成的异常.这是我的web.config设置:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="DevServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="DeveloperService"
behaviorConfiguration="DevServiceBehavior" >
<endpoint address="mtom"
binding="basicHttpBinding"
bindingConfiguration="Binding_DevService"
contract="DeveloperService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="Binding_DevService"
messageEncoding="Mtom"
openTimeout="00:02:00"
sendTimeout="00:02:00"
maxBufferPoolSize ="41943040"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="500"
maxArrayLength="20000000"
maxStringContentLength="20000000" />
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud) 我目前正在使用以下代码注册WCF服务:
var factory = new DefaultServiceHostFactory();
RouteTable.Routes.Add(new ServiceRoute("XXXEndPoint", factory, IXXXEndPoint)));
Run Code Online (Sandbox Code Playgroud)
这一切都很好,但我还需要更改阅读器配额设置的MaxStringContentLength属性.似乎使用默认值8192,无论我是否尝试更改此设置,我想这是来自DefaultServiceModel?
是否有任何合适的钩子来覆盖DefaultServiceModel上的这个设置,或者我应该派生自己的服务主机/模型类,还是我以错误的方式解决这个问题?
任何建议赞赏.
编辑:请注意,绑定的配置必须以编程方式执行(而不是通过配置文件).
谢谢
我最近转换了一些Silverlight 3 WCF服务以使用新的二进制http绑定.长字符串经常被发送到服务器以便在这些服务中进行反序列化,之前我曾用它来确保可以正确读取数据.但是,使用新绑定我找不到添加元素的正确位置:
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding maxReadPoolSize="2147483647" maxSessionSize="2147483647" maxWritePoolSize="2147483647"/>
<httpTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"/>
</binding>
</customBinding>
Run Code Online (Sandbox Code Playgroud)
这是一次尝试:
<customBinding>
<binding name="binaryHttpBinding">
<binaryMessageEncoding maxReadPoolSize="2147483647" maxSessionSize="2147483647" maxWritePoolSize="2147483647"/>
<httpTransport maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"/>
<textMessageEncoding>
<readerQuotas maxDepth="32" maxStringContentLength="5242880"
maxArrayLength="200000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
</binding>
</customBinding>
Run Code Online (Sandbox Code Playgroud)
这导致了其他问题 - 在同一个绑定中使用二进制编码和textMessageEncoding似乎不是一个好主意.因此,仅使用二进制编码,如何增加读取器配额以允许对大字符串进行反序列化?
silverlight maxstringcontentlength wcf-binding silverlight-3.0
请告诉我InputFile.PostedFile.ContentLength测量的单位.我需要确保文件小于500k.
谢谢.
wcf ×2
asp.net ×1
file-upload ×1
filesize ×1
routetable ×1
silverlight ×1
vb.net ×1
wcf-binding ×1
web-services ×1
xmlreader ×1