【问题标题】:Silverlight 4 & WCF Cannot insert data record with a long sting as a method paramSilverlight 4 & WCF 无法插入带有长字符串的数据记录作为方法参数
【发布时间】:2011-04-21 05:03:52
【问题描述】:

我正在开发一个使用 Silverlight 4 和 WCF 的项目。所有的网络方法,除了一个都工作正常。在 Silverlight 中,我使用自定义 xaml 编写器编写字符串,我想将字符串保存在数据库中。使用Web服务上的Insert方法,只要字符串参数不太大,我就可以插入数据。尝试插入由 xaml 编写器创建的字符串时,出现错误。我使用 Fiddler 来跟踪错误,我得到了 HTTP 400 错误。我在许多帖子中读到,我需要更改 Web 应用程序中的服务托管和 Silverlight 应用程序的客户端配置中的配置设置。我已经进行了我可以在网上找到的所有更改。我不知道还能尝试什么,而且我的资源已经用完了。当我将 xaml 字符串粘贴到记事本中并保存时,该文件只有 425 KB。这里是我对每个配置文件所做的更改。希望有人能指出我遗漏的任何内容。感谢您查看我的问题。

web 应用中的 web.config 文件:

     <system.serviceModel>
<behaviors>
    <serviceBehaviors>
        <!-- Enable the serializer to serialize greater number of records -->
        <behavior name="CustomServiceBehavior">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="false"/>
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
    </serviceBehaviors>
</behaviors>
 <bindings>
   <basicHttpBinding>
    <binding name="CustomBinding">
     <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647"
      maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
   </basicHttpBinding>

ServiceReferences.ClientConfig:

<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_DBService" maxBufferSize="2147483647"
                maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost.:49436/BuilderWebService/DBService.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_DBService"
            contract="ServiceReference1.DBService" name="BasicHttpBinding_DBService" />
    </client>
</system.serviceModel>

【问题讨论】:

    标签: silverlight wcf


    【解决方案1】:

    在您的 web.config 中的绑定标签中,您应该添加属性:maxBufferPoolSize、maxReceivedMessageSize、maxBufferSize

      <basicHttpBinding>
          <binding name="CustomBinding"
              maxBufferPoolSize="2147483647"
              maxReceivedMessageSize="2147483647"
              maxBufferSize="2147483647">
              <readerQuotas maxDepth="2147483647"
                            maxArrayLength="2147483647"
                            maxBytesPerRead="2147483647"
                            maxNameTableCharCount="2147483647"
                            maxStringContentLength="2147483647" />
          </binding>
      </basicHttpBinding>
    

    在我的示例中,我提供了尺寸的最大值,但您可以定义实际需要的尺寸。希望对你有帮助。

    【讨论】:

    • 我对 web.config 文件进行了更改,但仍然收到以下错误:远程服务器返回错误:未找到。我用一个小字符串测试了 web 方法,它运行良好。我仍然对传递给方法的较大 xaml 字符串有问题。
    • 尝试将maxStringContentLength="&lt;required size&gt;"属性添加到客户端和服务器配置的readerQuotas标签
    • 添加 maxStringContentLength 属性有效。我检查了数据库,一切正常。非常感谢您的帮助!多亏了你,我现在可以继续前进了。
    • 我很高兴它有效。您能否将我的回复标记为答案?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多