【问题标题】:Error sending large byte array发送大字节数组时出错
【发布时间】:2011-09-02 12:39:48
【问题描述】:

我有 WCF 服务,我通过它在数据库中添加数据。它工作正常,但是当我尝试发送大字节 [] 时,它返回“远程服务器返回错误:未找到”。

web.config

    <?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="JabsBaseConnectionString" connectionString="Data Source=TAHASAGHIR-PC\SQLEXPRESS;Initial Catalog=JabsBase;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>
    </compilation>
    <httpRuntime maxRequestLength="2097151" useFullyQualifiedRedirectUrl="true"/>
  </system.web>
  <system.serviceModel>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="SendLargeChat"
                 allowCookies="false"
                 bypassProxyOnLocal="false" 
                 maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="2147483647"
                 maxBufferSize="2147483647"
                 closeTimeout="10:00:00"
                 openTimeout="10:00:00"
                 receiveTimeout="10:00:00"
                 sendTimeout="10:00:00"
                 transferMode="Streamed">
          <readerQuotas 
            maxArrayLength="2147483647"
            maxBytesPerRead="2147483647"
            maxDepth="2147483647"
            maxNameTableCharCount="2147483647"
            maxStringContentLength="2147483647" />
        </binding>
      </basicHttpBinding>      
    </bindings>
    <services>
      <service name="Prototype.SendChatService" behaviorConfiguration="Prototype.SendChatServiceBehavior">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="SendLargeChat" contract="Prototype.SendChatService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>      
    </services>    
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="Prototype.SendChatServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

ServiceReferences.ClientConfig

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>        
        <binding name="BasicHttpBinding_ISendChatService" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <security mode="None" />
        </binding>
      </basicHttpBinding>      
    </bindings>
    <client>      
      <endpoint address="http://localhost:53756/PrototypeSite/SendChatService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISendChatService"
        contract="SendChatService.ISendChatService" name="BasicHttpBinding_ISendChatService" />
    </client>
  </system.serviceModel>
</configuration>

请求 发布http://localhost:53756/PrototypeSite/SendChatService.svc HTTP/1.1 主机:本地主机:53756 连接:保持活动 推荐人:http://localhost:53756/PrototypeSite/ClientBin/Prototype.xap 内容长度:1348176 肥皂动作:“http://tempuri.org/ISendChatService/addMsg” 内容类型:文本/xml;字符集=utf-8 接受:/ 用户代理:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.68 Safari/534.24 接受编码:gzip、deflate、sdch 接受语言:en-US,en;q=0.8 接受字符集:ISO-8859-1,utf-8;q=0.7,*;q=0.3

回应 HTTP/1.1 400 错误请求 服务器:ASP.NET 开发服务器/10.0.0.0 日期:格林威治标准时间 2011 年 5 月 26 日星期四 17:48:00 X-AspNet-版本:4.0.30319 缓存控制:私有 内容长度:0 连接:关闭

【问题讨论】:

    标签: silverlight wcf


    【解决方案1】:

    404/Not Found 是 Silverlight 针对所有服务器错误报告的错误。如果您想知道从服务器返回的实际错误,您可以使用Fiddler 之类的东西来查看正在发送和接收的内容,包括包含服务器返回的实际错误代码和错误消息的标头。

    【讨论】:

    • 谢谢大卫...我正在编辑我的原始帖子!请检查请求和响应。
    • Bad Request 可能是多种情况:发送的xml坏了(可以在Fiddler中查看,看看请求数据是否可以看成XML),请求使用的合约不是与服务器相同(如果您是从相同的 WCF 代码编写的,则不太可能),或者请求违反了范围检查。请求是否超过 64KB?它可能会破坏 WCF 服务中设置的默认 MaxReceivedMessageSize 限制。
    【解决方案2】:

    我认为你应该应用相同的

    <readerQuotas ...
    

    在客户端上。

    【讨论】:

      【解决方案3】:

      尝试将 executionTimeout 设置添加到您的 HTTPRuntime 设置

      <httpRuntime executionTimeout="110" maxRequestLength="..." />
      

      【讨论】:

        【解决方案4】:

        根据我的经验,我收到了一个错误,因为即使服务器上的服务被配置为接收大量数据,http 运行时却没有。确保您的 httpRuntime 具有适当的 maxRequestLength。

        【讨论】:

          【解决方案5】:

          您还可以打开 WCF 日志记录以获取更多信息。将以下内容添加到您的 web.config:

          <system.diagnostics>
              <sources>
                  <source name="System.ServiceModel"
                            switchValue="Information, ActivityTracing"
                            propagateActivity="true">
                      <listeners>
                          <add name="traceListener"
                               type="System.Diagnostics.XmlWriterTraceListener"
                               initializeData= "c:\log\Traces.svclog" />
                      </listeners>
                  </source>
              </sources>
          </system.diagnostics>
          

          【讨论】:

            【解决方案6】:

            对不起,我的回答是错误的!!忽略它

            我会在几个小时内删除它,只让有cmets的人看到它。

            在 SOAP 中发送字节数组。

            每个字节将以&lt;byte&gt;128&lt;/byte&gt; 或类似名称传输,这意味着平均需要多出 10 倍。

            改用 base64 字符串 - 因此将您的属性定义为字符串并将其填充为 base64 字符串。

            【讨论】:

            • Aliostad,感谢您的快速回复!能否请您详细介绍一下流程,如何将字节数组转换为base64字符串,反之亦然?
            • 哇。知道这真的很有用。您有参考资料来解释这一点吗?
            • 这听起来不对...我很确定 byte[] 被序列化程序编码为 Base64 字符串...例如webservices20.blogspot.com/2010/10/…
            • 抱歉误导...见我的cmets。一旦每天都学到一些东西
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-09-05
            • 1970-01-01
            • 1970-01-01
            • 2013-12-15
            相关资源
            最近更新 更多