-1

Web サーバーから zip ファイルをダウンロードするWCFのWeb サービスがあります。そのファイルをダウンロードするためにFtpWebRequestを使用しています。これが私のコードです

public byte[] DownloadFile(string fileName)
    {
        int bytesRead = 0;


        String downloadUrl = String.Format("{0}{1}/{2}", "ftp://xx.xx.xxx.xxx/datatransfer/", "folder", fileName);
        FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(downloadUrl);
        req.Method = WebRequestMethods.Ftp.DownloadFile;
        req.Credentials = new NetworkCredential("uname", "pass");
        Stream reader = req.GetResponse().GetResponseStream();
        //FileStream fileStream = new FileStream(localDestinationFilePath, FileMode.Create);
        byte[] buffer = new byte[2048];
        while (true)
        {
            bytesRead = reader.Read(buffer, 0, buffer.Length);

            if (bytesRead == 0)
                break;

            //fileStream.Write(buffer, 0, bytesRead);
        }
        return buffer;
    }

ネットワークがダウンしていると、ダウンロードに時間がかかり、エラーが発生します

リモート サーバーがエラーを返しました: NotFound。タイプ 'System.ServiceModel.CommunicationException' の例外が System.ServiceModel.ni.dll で発生しましたが、ユーザー コードで処理されませんでした

これが私のweb.configです

<?xml version="1.0"?>
<configuration>

 <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
 </appSettings>
 <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" maxRequestLength="409600"/>
 </system.web>
 <system.serviceModel>
   <bindings>
     <basicHttpBinding>
      <!--<binding maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" receiveTimeout="00:10:00" closeTimeout="00:10:00">
      <security mode="None" />
    </binding>-->
    <binding closeTimeout="01:10:00"
      openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00"
      maxBufferSize="2147483646" maxBufferPoolSize="2147483646" maxReceivedMessageSize="2147483646"
       transferMode="StreamedRequest">
      <readerQuotas maxDepth="2147483646" maxStringContentLength="2147483646" maxArrayLength="2147483646"
        maxBytesPerRead="2147483646" maxNameTableCharCount="2147483646" />
      <security mode="None">             
      </security>
    </binding>    
  </basicHttpBinding>    
</bindings>   

<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
  <protocolMapping>
    <add binding="basicHttpsBinding"  scheme="https"/>
  </protocolMapping>    
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
 </system.serviceModel>
 <system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/>
   <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
  -->
   <directoryBrowse enabled="true"/>
 </system.webServer>

</configuration>

ここに私のServiceReferences.ClientConfigがあります

<configuration>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647" closeTimeout="01:10:00"
                      openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00" maxReceivedMessageSize="2147483647">
                <security mode="None" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localIP/WebService/Service1.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
            contract="MyService.IService1" name="BasicHttpBinding_IService1" />
    </client>
</system.serviceModel>

ネットワークがダウンしているときに大きなファイルをダウンロードする方法はありますか? web.config に変更はありますか?

4

1 に答える 1