大型二进制(字节[])通过WCF文件传输 [英] Large Binary (byte[]) File transfer through WCF

查看:254
本文介绍了大型二进制(字节[])通过WCF文件传输的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个WCF服务,可以让我从客户端发送大量的二进制文件的服务。

我如何过我只是能够成功文件传输可达3-4MB。 (我失败时,我尝试传输4.91MB和关闭过程中的任何东西以后)

我得到的,如果我尝试发送4.91MB文件中的错误是:

异常消息://本地主机:56198 /服务在接收HTTP响应 HTTP发生错误。 SVC 。这可能是由于服务端点未使用HTTP协议绑定。这也可能是由于一个HTTP请求上下文被中止的服务器(可能是由于该服务正在关闭)。请参阅服务器日志的更多细节。

内部异常消息:的基础连接已关闭:在发生意外错误接收

内部异常消息:无法读取传输连接的数据:一个现有的连接被强行关闭远程主机

内部异常消息:一个现有的连接被强行关闭远程主机

此错误发生在客户端只要字节[]文件被发送作为方法参数到暴露服务方法。

我有一个断点在服务方法的第一线,以防sucessfull文件传输(以下3MB)那个破品脱被击中,并在文件被转移。如何以往在这种情况下,只要方法被调用时,错误出现。在服务的断点未命中的情况下此错误的。

我要贴我的服务Web.config文件和ASP页(客户端)的Web.config我的部分。如果您还需要将文件发送和接受文件code,让我知道,我会送这一点。

服务Web.Config

 < system.serviceModel>
<绑定>
  < basicHttpBinding的>
    <绑定名称=basicHttpEndpointBindingcloseTimeout =1点○一分00秒
      openTimeout =1时01分00秒receiveTimeout =1点10分○○秒的SendTimeout =1时01分00秒
      allowCookies =假bypassProxyOnLocal =假hostNameComparisonMode =StrongWildcard
      maxBufferSize =2147483646maxBufferPoolSize =2147483646maxReceivedMessageSize =2147483646
      messageEncoding =MTOMtextEncoding =UTF-8transferMode =StreamedRequest
      useDefaultWebProxy =真正的>
      < readerQuotas MAXDEPTH =2147483646maxStringContentLength =2147483646maxArrayLength =2147483646
        maxBytesPerRead =2147483646maxNameTableCharCount =2147483646/>
      <安全模式=无>
        <交通运输clientCredentialType =无proxyCredentialType =无
          境界=/>
        <消息clientCredentialType =用户名algorithmSuite =默认/>
      < /安全>
    < /装订>
  < / basicHttpBinding的>
< /绑定>
    <服务>
        <服务behaviorConfiguration =DragDrop.Service.ServiceBehaviorNAME =DragDrop.Service.Service>
            <端点地址=绑定=basicHttpBinding的bindingConfiguration =basicHttpEndpointBinding合同=DragDrop.Service.IService>
                <身份>
                    < D​​NS值=本地主机/>
                < /身分>
            < /端点>
            <端点地址=MEX绑定=mexHttpBinding合同=IMetadataExchange接口/>
        < /服务>
    < /服务>
    <行为>
        < serviceBehaviors>
            <行为NAME =DragDrop.Service.ServiceBehavior>
                < serviceMetadata httpGetEnabled =真/>
                < serviceDebug includeExceptionDetailInFaults =FALSE/>
      < D​​ataContractSerializer的maxItemsInObjectGraph =2147483646/>
            < /行为>
        < / serviceBehaviors>
    < /行为>
< /system.serviceModel>
 

客户端(Asp.net页)Web.config中

 < system.serviceModel>
<绑定>
   < basicHttpBinding的>
      <绑定名称=BasicHttpBinding_IServicecloseTimeout =00:01:00
         openTimeout =〇时01分00秒receiveTimeout =0时十分00秒的SendTimeout =〇时01分00秒
         allowCookies =假bypassProxyOnLocal =假hostNameComparisonMode =StrongWildcard
         maxBufferSize =2147483646maxBufferPoolSize =2147483646maxReceivedMessageSize =2147483646
         messageEncoding =MTOMtextEncoding =UTF-8transferMode =StreamedResponse
         useDefaultWebProxy =真正的>
         < readerQuotas MAXDEPTH =2147483646maxStringContentLength =2147483646maxArrayLength =2147483646
            maxBytesPerRead =2147483646maxNameTableCharCount =2147483646/>
         <安全模式=无>
            <交通运输clientCredentialType =无proxyCredentialType =无
               境界=>
               < extendedProtectionPolicy policyEnforcement =从不/>
            < /运输>
            <消息clientCredentialType =用户名algorithmSuite =默认/>
         < /安全>
      < /装订>
   < / basicHttpBinding的>
< /绑定>

<行为>
  < endpointBehaviors>
    <行为NAME =debuggingBehaviour>
      < D​​ataContractSerializer的maxItemsInObjectGraph =2147483646/>
    < /行为>
  < / endpointBehaviors>
< /行为>

<客户端>
   <端点地址=HTTP://本地主机:56198 / Service.svc绑定=basicHttpBinding的
      bindingConfiguration =BasicHttpBinding_IService合同=ServiceReference.IService
      NAME =BasicHttpBinding_IServicebehaviorConfiguration =debuggingBehaviour/>
< /客户>
< /system.serviceModel>
 

解决方案

(虽然我同意的流传输将是preferrable,下面应该让工作没有任何其他的变化)

您还需要增加在Web.config的最大消息长度:

 <结构>
  <的System.Web>
  <的httpRuntime maxMessageLength =409600
    executionTimeoutInSeconds =300/>
  < /system.web>
< /结构>
 

这将设置最大消息长度为400 MB(参数单位​​为KB)。检查这个MSDN页面以了解更多信息。

I am trying to build a WCF service that allows me to send large binary files from clients to the service.

How ever I am only able to successfully transfer files up to 3-4MB. (I fail when i try to transfer 4.91MB and off course any thing beyond)

The Error I get if I try to send the 4.91MB file is:

Exception Message: An error occurred while receiving the HTTP response to http://localhost:56198/Service.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Inner Exception Message: The underlying connection was closed: An unexpected error occurred on a receive.

Inner Exception Message: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

Inner Exception Message: An existing connection was forcibly closed by the remote host

This error occurs at client side as soon as the byte[] file is sent as a method parameter to the exposed service method.

I have a breakpoint at the service method's first line, in case of sucessfull file transfers (below 3MB) that break pint is hit and the file gets transfered. How ever in this case as soon as the method is called, the error comes. The breakpoint in the service is not hit in case of this error.

I am going to paste my sections of my Service Web.config and Asp Page (Client) Web.config. If you also require the code that send the file and accepts the file, let me know, I'll send that as well.

Service Web.Config

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="basicHttpEndpointBinding" closeTimeout="01:01:00"
      openTimeout="01:01:00" receiveTimeout="01:10:00" sendTimeout="01:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="2147483646" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646"
      messageEncoding="Mtom" textEncoding="utf-8" transferMode="StreamedRequest"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646"
        maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>        
  </basicHttpBinding>      
</bindings>
    <services>
        <service behaviorConfiguration="DragDrop.Service.ServiceBehavior" name="DragDrop.Service.Service">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpEndpointBinding" contract="DragDrop.Service.IService">
                <identity>
                    <dns value="localhost"/>
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="DragDrop.Service.ServiceBehavior">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="false"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

Client (Asp.net page) Web.Config

<system.serviceModel>
<bindings>
   <basicHttpBinding>
      <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
         openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
         allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
         maxBufferSize="2147483646" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646"
         messageEncoding="Mtom" textEncoding="utf-8" transferMode="StreamedResponse"
         useDefaultWebProxy="true">
         <readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646"
            maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
         <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
               realm="">
               <extendedProtectionPolicy policyEnforcement="Never" />
            </transport>
            <message clientCredentialType="UserName" algorithmSuite="Default" />
         </security>
      </binding>
   </basicHttpBinding>
</bindings>

<behaviors>
  <endpointBehaviors>
    <behavior name="debuggingBehaviour">
      <dataContractSerializer maxItemsInObjectGraph="2147483646" />
    </behavior>
  </endpointBehaviors>
</behaviors>

<client>
   <endpoint address="http://localhost:56198/Service.svc" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference.IService"
      name="BasicHttpBinding_IService" behaviorConfiguration="debuggingBehaviour" />
</client>
</system.serviceModel>

解决方案

(While I agree that streaming transfer would be preferrable, the below should make it work without any other changes)

You also need to increase the maximum message length in the Web.config:

<configuration>
  <system.web>
  <httpRuntime maxMessageLength="409600"
    executionTimeoutInSeconds="300"/>
  </system.web>
</configuration>

This will set the maximum message length to 400 MB (parameter is in kB). Check this MSDN page for more information.

这篇关于大型二进制(字节[])通过WCF文件传输的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆