• WCF服务的程序字符串过长...


    编写基于WCF服务的程序时,向WCF服务端发送一长串的HTML源码,结果客户端收到提示如下:

    格式化程序尝试对消息反序列化时引发异常: 对操作“AddArticle”的请求消息正文进行反序列化时出现错误。读取 XML 数据时,超出最大字符串内容长度配额 (8192)。通过更改在创建 XML 读取器时所使用的 XmlDictionaryReaderQuotas 对象的 MaxStringContentLength 属性,可增加此配额。 第 64 行,位置为 79。

    主要是maxStringContentLengthmaxReceivedMessageSize的设置会影响到消息的发送和接收,于是全部改为2MB大小,即2097152。

    客户端app.config修改:

            <bindings>
                <basicHttpBinding>
                    <binding name="BasicHttpBinding_ShareService" closeTimeout="00:01:00"
                        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                        maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="2097152"
                        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                        useDefaultWebProxy="true">
                        <!-- Reset maxStringContentLength for deserialize -->
                        <readerQuotas maxDepth="32" maxStringContentLength="2097152" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                        <security mode="None">
                            <transport clientCredentialType="None" proxyCredentialType="None"
                                realm="" />
                            <message clientCredentialType="UserName" algorithmSuite="Default" />
                        </security>
                    </binding>
                </basicHttpBinding>
            </bindings>

    服务端web.config修改:

    	<system.serviceModel>
        <!-- add for the message size -->
        <bindings>
          <basicHttpBinding>
            <binding name="NewBinding2MB" maxReceivedMessageSize="2097152">
              <readerQuotas maxStringContentLength="2097152" />
            </binding>
          </basicHttpBinding>
        </bindings>
        <!-- add for the message size -->
    		<behaviors>
    			<serviceBehaviors>
    				<behavior name="Web.WCF.ShareServiceBehavior">
    					<serviceMetadata httpGetEnabled="true"/>
    					<serviceDebug includeExceptionDetailInFaults="false"/>
    				</behavior>
    			</serviceBehaviors>
    		</behaviors>
    		<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    		<services>
    			<service behaviorConfiguration="Web.WCF.ShareServiceBehavior" name="Web.WCF.ShareService">
    				<endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding2MB" contract="Web.WCF.ShareService"/>
    				<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    			</service>
    		</services>
    	</system.serviceModel>
  • 相关阅读:
    python3监控网站状态
    暴力屏蔽80访问失败的用户
    python3爬取中国药学科学数据
    python3发邮件脚本
    OOP AOP
    lambda
    jni
    Gradle史上最详细解析
    supersocket 遇到的Failed to initialize 和 log4net用法
    在c#中利用keep-alive处理socket网络异常断开的方法
  • 原文地址:https://www.cnblogs.com/weixing/p/2958069.html
Copyright © 2020-2023  润新知