Проблема с загрузкой многих файлов из WCF - PullRequest
0 голосов
/ 14 октября 2010

У меня проблема с сервисом WCF.Когда я загружаю 2 файла, все работает нормально (менее 1 минуты), но когда я пытаюсь загрузить более 3 файлов, происходит что-то плохое.Я жду и жду и ничего: / Каждый файл имеет около 1 МБ.

Dictionary<FileIdentifier, Stream> data = new Dictionary<FileIdentifier, Stream>();

 foreach (string path in paths)
 {

    using (var client = new ServiceClient())
    {
        var stream = client.GetFile(path);

        data[fileIdentifier] = stream;
     }

 }

Метод в службе WCF:

public Stream GetFile(string path)
        {
             FileStream fs = new FileStream(stream, FileMode.Open);
            fs.Close();
            return fs;

        }

Конфигурация службы WCF:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <system.serviceModel>
    <client />
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBindingConfiguration" closeTimeout="00:10:00"
          openTimeout="00:15:00" receiveTimeout="00:15:00" sendTimeout="00:15:00"
          allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2097152000" maxBufferPoolSize="524288000" maxReceivedMessageSize="2097152000"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
          useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="524288000"
            maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None"
              realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="FileServer.Service" behaviorConfiguration="FileServer.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/Design_Time_Addresses/Server.FileServer/Service/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" contract="FileServer.IService" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="FileServer.Service1Behavior">
          <!-- 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>
  </system.serviceModel>
  <system.web>
    <compilation debug="true" />
    <httpRuntime maxRequestLength="2097151" executionTimeout="1000" />
    <customErrors mode="RemoteOnly" />
  </system.web>
  <system.webServer>
    <directoryBrowse enabled="false" />
  </system.webServer>
</configuration>

Ответы [ 2 ]

3 голосов
/ 14 октября 2010

Вы не должны закрывать поток на стороне обслуживания.

Вот как бы вы поступили:

  1. Открытый поток на сервисе
  2. Обратный поток к клиенту
  3. Чтение потока на клиенте
  4. Закрыть поток на клиенте
  5. WCF позаботится о закрытии потока услуг для вас
1 голос
/ 14 октября 2010

Вместо того, чтобы возвращать поток, считайте поток в байтовый массив и затем верните байтовый массив.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...