发送大字节数组时出错

问题描述

| 我有WCF服务,可以通过它在DB中添加数据。它工作正常,但是当我尝试发送大字节[]时,它返回\“远程服务器返回错误:NotFound \”。 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>
请求 POST http:// localhost:53756 / PrototypeSite / SendChatService.svc HTTP / 1.1 主机:localhost:53756 连接:保持活动状态 引荐来源:http:// localhost:53756 / PrototypeSite / ClientBin / Prototype.xap 内容长度:1348176 soapaction:\“ http://tempuri.org/ISendChatService/addMsg \” 内容类型:text / xml;字符集= utf-8 接受:/ 用户代理:Mozilla / 5.0(Windows NT 6.1)AppleWebKit / 534.24(KHTML,例如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日,星期四,格林尼治标准时间 X-AspNet版本:4.0.30319 缓存控制:私有 内容长度:0 连接:关闭     

解决方法

404 /未找到是针对所有服务器错误的错误Silverlight报告。如果您想知道从服务器返回的实际错误,可以使用Fiddler之类的东西查看发送和接收的内容,包括包含实际错误代码和服务器返回的错误消息的标头。     ,我想你应该也一样
<readerQuotas ...
在客户端上。     ,尝试将执行超时设置添加到您的HTTPRuntime设置
<httpRuntime executionTimeout=\"110\" maxRequestLength=\"...\" />
    ,以我的经验,我收到一个错误消息是因为即使服务器上的服务配置为接收大量数据,但http运行时却没有。确保您的httpRuntime具有适当的maxRequestLength。     ,您还可以打开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>
    ,对不起,我的答案不对!忽略它 我将在几个小时后将其删除,只允许有评论的人看到它。 不要在SOAP中发送字节数组。 每个字节将以
<byte>128</byte>
或类似的形式传输,这意味着平均要多花10倍。 请改用base64字符串-将属性定义为字符串,然后将其填充为base64字符串。