WCF problème avec le téléchargement d'un fichier volumineux, hébergé dans IIS

Je suis en train de télécharger de gros fichiers à un Service WCF hébergé dans IIS.

Je suis avec calme et méthode de diffusion.

Mais je ne suis pas capable de télécharger des fichiers qui est plus de 64 ko.

J'ai essayé beaucoup en changeant tous les liés à la taille des éléments dans web.config fichier, mais a échoué à résoudre le problème.

Voici mon code et de configuration, s'il vous plaît laissez-moi savoir si quelqu'un à trouver des problèmes dans le code et comment puis-je réparer.

Contrat D'Opération

[OperationContract]
[WebInvoke(UriTemplate = "/UploadImage/{filename}")]
bool UploadImage(string filename, Stream image);

Mise en œuvre de Contrat d'Opération

public bool UploadImage(string filename, Stream image)
{
    try
    {
        string strFileName = ConfigurationManager.AppSettings["UploadDrectory"].ToString() + filename;

        FileStream fileStream = null;
        using (fileStream = new FileStream(strFileName, FileMode.Create, FileAccess.Write, FileShare.None))
        {
            const int bufferLen = 1024;
            byte[] buffer = new byte[bufferLen];
            int count = 0;
            while ((count = image.Read(buffer, 0, bufferLen)) > 0)
            {
                fileStream.Write(buffer, 0, count);
            }
            fileStream.Close();
            image.Close();
        }

        return true;
    }
    catch (Exception ex)
    {
        return false;
    }
}

web.config

  <system.serviceModel>
    <services>
      <service name="Service" behaviorConfiguration="ServiceBehavior">
        <endpoint address="http://localhost/WCFService1" behaviorConfiguration="web"
                  binding="webHttpBinding" bindingConfiguration="webBinding"
                  contract="IService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="webBinding"
            transferMode="Streamed"
            maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
            openTimeout="00:25:00" closeTimeout="00:25:00" sendTimeout="00:25:00" 
            receiveTimeout="00:25:00" >
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

et

<httpRuntime maxRequestLength="2097151"/>

Service est hébergé dans hébergés dans IIS

Code côté Client (application console)

private static void UploadImage()
{
    string filePath = @"F:\Sharath\TestImage\TextFiles\SampleText2.txt";
    string filename = Path.GetFileName(filePath);

    string url = "http://localhost/WCFService1/Service.svc/";
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + "UploadImage/" + filename);

    request.Accept = "text/xml";
    request.Method = "POST";
    request.ContentType = "txt/plain";

    FileStream fst = File.Open(filePath, FileMode.Open);
    long imgLn = fst.Length;
    fst.Close();
    request.ContentLength = imgLn;

    using (Stream fileStream = File.OpenRead(filePath))
    using (Stream requestStream = request.GetRequestStream())
    {
            int bufferSize = 1024;
            byte[] buffer = new byte[bufferSize];
            int byteCount = 0;
            while ((byteCount = fileStream.Read(buffer, 0, bufferSize)) > 0)
            {
                requestStream.Write(buffer, 0, byteCount);
            }
    }

    string result;

    using (WebResponse response = request.GetResponse())
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
            result = reader.ReadToEnd();
    }

    Console.WriteLine(result);
}

Avec beaucoup de code, je suis en mesure de télécharger des 64 ko de fichier, mais lorsque je tente de télécharger un fichier de plus de 64 ko à la taille, j'obtiens le message d'erreur tel que,

The remote server returned an error: (400) Bad Request


j'ai fait ce que vous avez dit mais j'ai toujours se même problème, c'est comment ma config ressemble maintenant, pouvez-vous s'il vous plaît dites-moi ce qui manque encore ici

<services>
  <service name="Service" behaviorConfiguration="ServiceBehavior">
    <endpoint address="http://localhost/WCFService1" behaviorConfiguration="web"
              binding="webHttpBinding" bindingConfiguration="webBinding"
              contract="IService">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding transferMode="Streamed"
             maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
             openTimeout="00:25:00" closeTimeout="00:25:00" sendTimeout="00:25:00" receiveTimeout="00:25:00"
             name="webBinding">
      <readerQuotas maxDepth="64" 
                    maxStringContentLength="2147483647" 
                    maxArrayLength="2147483647" 
                    maxBytesPerRead="2147483647" 
                    maxNameTableCharCount="2147483647"/>
    </binding>
  </webHttpBinding>
</bindings>
Quel est le nom et l'espace de noms de votre classe?
toute solution finale avec l'intégralité du code source de l'échantillon de travail à ce sujet ?

OriginalL'auteur Sharath | 2011-06-11