.NET Web服务最大数组长度配额

时间:2014-06-28 06:33:17

标签: c# web-services web-config windows-applications

当我尝试从客户端接收(下载)我的服务中的record.wav(28K)时,我写了一个聊天窗口应用程序。有一个错误:

格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数http://tempuri.org/:DownloadFileResponse时出错。 InnerException消息是'反序列化BerryWindowsApplication.BerryWebService.DownloadFileResponseBody类型的对象时出错。读取XML时已超出最大数组长度配额(16384)。

我搜索并发现我应该在Edit WCF配置中创建新的绑定。我将MaxBufferSize,MaxReceivemessageSize,MaxBufferPoolSize,MaxArrayLenght,MaxBytesperRead更改为2147483647并将maxdepth更改为32并将transfermode更改为缓冲并将messageencoding更改为Mtom,但是存在相同的错误。 以下代码用于此程序:

在网络服务方面:

[WebMethod()]
public byte[] DownloadFile(string FName)
{
   Byte[] bytes = System.IO.File.ReadAllBytes(@"E:\Files\"+FName);
   return bytes;
}
webconfig中的

 <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="binding" maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
      maxReceivedMessageSize="2147483647" messageEncoding="Mtom">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="Transport">
        <transport clientCredentialType="Windows" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://192.168.0.106/Service.asmx"
   binding="basicHttpBinding" bindingConfiguration="binding"
   contract="BerryWebService.WebService" name="binding" />
</client>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>

在Windows应用程序端:

if (fdDownload.ShowDialog() == DialogResult.OK)
                {
                    string s = sr[2].ToString().Split('\\').Last();
                    var byteArray = bs.DownloadFile(s);
                   byte[] b1= Encoding.UTF8.GetBytes(byteArray.ToString());
                    System.IO.File.WriteAllBytes(fdDownload.FileName, b1);
                    FileStream fs = new FileStream(fdDownload.FileName, FileMode.CreateNew, FileAccess.Write);
                    fs.Write(b1, 0, b1.Length);
                    fs.Flush();
                    fs.Close();
                    cn.Open();
                    MessageBox.Show("File downloaded Successfully", "Warning", MessageBoxButtons.OK);

0 个答案:

没有答案