简体   繁体   English

WCF通讯问题

[英]WCF communication problem

In my WCF application I receive an image in base64String format along with some other images.. In order to test my application I have created a small.aspx page which will send firstname, last name and base64string(image:size 10Kb) to the WCF Sevice.在我的 WCF 应用程序中,我收到了 base64String 格式的图像以及其他一些图像。为了测试我的应用程序,我创建了一个 small.aspx 页面,它将把名字、姓氏和 base64string(image:size 10Kb) 发送到 WCF服务。 I am getting the error "The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'SaveData'. 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 15301."我收到错误“格式化程序在尝试反序列化消息时引发异常:反序列化操作'SaveData'的请求消息正文时出错。读取XML数据时已超出最大字符串内容长度配额(8192)。此配额可以通过更改创建 XML 阅读器时使用的 XmlDictionaryReaderQuotas object 上的 MaxStringContentLength 属性来增加。第 1 行,position 153。

If I send the strings without the base64string(image) i was able to debug the wcf Service code.如果我发送没有 base64string(image) 的字符串,我能够调试 wcf 服务代码。 But if I add the base64String I am getting this error.但是,如果我添加 base64String 我会收到此错误。 I have increased all binding values("maxReceivedMessageSize") and other values to maximum.我已将所有绑定值(“maxReceivedMessageSize”)和其他值增加到最大值。 Still I am getting this error.我仍然收到此错误。 Here is my web.config for client and Service.这是我的 web.config 用于客户端和服务。 Thanks and I really appreciate your help.谢谢,我真的很感谢你的帮助。

Client Web.config客户端 Web.config

 <system.serviceModel>  
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IRESTService1" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" 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>
    <client>
      <endpoint address="http://localhost:10255/RESTService1.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IRESTService1" contract="ServiceReference1.IRESTService1"
        name="BasicHttpBinding_IRESTService1" />
    </client>
  </system.serviceModel>

Service web.config服务 web.config

<system.serviceModel>       
    <bindings>
      <basicHttpBinding>
        <binding name="BasicBinding1" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>      

    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <services>
      <service name="RESTService1">
        <endpoint address=""
          binding="basicHttpBinding" name="MainHttpPoint" contract="RESTService1"  bindingConfiguration="BasicBinding1" />       
      </service>
    </services>

    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>-->
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>   

Add these lines inside Binding tag in web.config file在 web.config 文件中的Binding标记内添加这些行

<binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"   maxBytesPerRead="2147483647" />
</binaryMessageEncoding>
<httpTransport  decompressionEnabled="True" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"/>

MSDN: binaryMessageEncoding MSDN:二进制消息编码

hope this help希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM