繁体   English   中英

通过WCF服务的大文件

[英]large file through WCF service

类似的问题不断涌现,我查看了所有这些问题。 看来没有人能解决我的问题。

-更新:-

我正在尝试使用WCF服务将文档(pdf,doc或其他文件)上传到数据库。 对该服务的调用如下所示:

using (var cw = new WCFClientWrapper<ICommonService>())
{
    cw.Channel.DocumentInsert(content, filename, contentType);
}

这是合同的签字:

[OperationContract]
void DocumentInsert(byte[] content, string fileName, string contentType);

请注意,我正在传递内容的字节数组,因为这是将内容存储在DB中需要传递的内容。

-更新结束-

我可以成功上传一个小文件(kb)。 但是,当我尝试上传更大的内容(20kb)时,出现异常:

格式化程序尝试反序列化消息时引发异常:反序列化“ DocumentInsert”操作的请求消息正文时出错。 读取XML数据时,已超出最大数组长度配额(16384)。 通过更改在创建XML阅读器时使用的XmlDictionaryReaderQuotas对象上的MaxArrayLength属性,可以增加此配额。 第1行,位置31774。

该错误似乎很明显...只需增加MaxArrayLength。 我这样做没有任何成功的结果。 以下是我的web.configs中的相关部分

客户:

<system.serviceModel>

    <behaviors>
      <endpointBehaviors>
        <behavior name="SecureBehavior">
        </behavior>
      </endpointBehaviors>
    </behaviors>

    <bindings>
      <basicHttpBinding>
        <binding name="WSHttpBinding_Service" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="262144" messageEncoding="Text"
          textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="5242880" />
        </binding>
      </basicHttpBinding>
    </bindings>

    <client>
      <endpoint address="http://dev.svc.someurl.com/CommonService.svc"
                binding="basicHttpBinding"
                bindingConfiguration="WSHttpBinding_Service"
                behaviorConfiguration="SecureBehavior"
                contract="MyApp.Contracts.ServiceContracts.ICommonService"
                name="MyApp.Contracts.ServiceContracts.ICommonService">
      </endpoint>
    </client>

  </system.serviceModel>

服务:

<system.serviceModel>
    <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="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

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

    <services>
      <service name="MyApp.WCFServices.CommonService">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="MyBasicHttpBinding"
                  contract="MyApp.Contracts.ServiceContracts.ICommonService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
      <service name="MyApp.WCFServices.AccountService">
        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="MyBasicHttpBinding"
                  contract="MyApp.Contracts.ServiceContracts.IAccountService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

附加诊断显示:

  • 构造服务 :无错误/警告
  • 开放服务 :警告-找不到配置评估上下文-找不到匹配的标签。 添加了默认端点。
  • 收听“ http://dev.svc.someurl.com/CommonService.svc” :无错误/警告
  • 处理消息1 :无错误/警告
  • 处理动作“ http://tempuri.org/ICommonService/DocumentInsert”。 :抛出我一开始就写的异常。

任何帮助表示赞赏。

几个月前,我遇到了同样的例外。 要向/从WCF服务发送/接收大数据,必须设置transferMode="Streamed" 当将transfermode用作Buffered时,实际上是在上载/下载之前将整个文件放入内存中。 因此,Web客户端和WCF服务主机上都需要大缓冲区。而流传输可以通过消除对大内存缓冲区的需求来提高服务的可伸缩性。 有关transfermode的更多信息,请参见TransferMode枚举上的MSDN文章。

好吧,经过一天的挣扎,我终于找到了一个问题。 我只需要确保WCF web.config中的标记名称与名称空间和服务名称匹配即可:

<service name="ServicesImplementation.WcfServices.CommonService">

不幸的是,根据我提供的信息,你们不会看到这些东西。

暂无
暂无

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

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