2011-09-08 73 views
0

我必須要一個名爲uploadFile的web服務方法,該方法獲取一個參數爲base64str並將其作爲文件記錄到指定的地址中。 但是,我有一個問題。該方法不允許上傳超過350 KB的文件。否則,我可以上傳小於300 KB的文件,例如zip,jpg,txt。另外, 當我嘗試上傳超過350 KB的文件時,一個進程可以在服務器上持續工作。文件發佈問題 - ASP.Net

過程:

Image Name : w3wp.exe, UserName : ASP.Net v4.0, CPU : 50, Description : IIS Worker Process 

有時服務器CPU前進到100%

代碼:

* encodedFile = Base64Str as format 

    string postString = string.Format("userName={0}&userVendor={1}&vendorKey={2}&base64FileStr={3}&guid={4}&fileName={5}",         "kadi", "şifre", "key", encodedFile, guid, strFilename); 


       string localHttpPostUrl = userGatewayAddress + "uploadFile"; 

       ASCIIEncoding encoding = new ASCIIEncoding(); 

       Stream newStream = null; 

       HttpWebResponse response = null; 

       Stream streamResponse = null; 

       StreamReader streamRead = null; 


       try 

       { 

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(localHttpPostUrl); 

        request.ContentType = "application/x-www-form-urlencoded"; 

        request.Method = "POST"; 



        byte[] buffer = Encoding.UTF8.GetBytes(postString); 

        request.ContentLength = buffer.Length; 


        newStream = request.GetRequestStream(); 

        newStream.Write(buffer, 0, buffer.Length); 

        newStream.Close(); 


        response = (HttpWebResponse)request.GetResponse(); 

        streamResponse = response.GetResponseStream(); 

        streamRead = new StreamReader(streamResponse); 


        Char[] readBuffer = new Char[256]; 

        ret = string.Empty; 

        int totalCharCount = 0; 

        int count = streamRead.Read(readBuffer, 0, 256); 

        while (count > 0) 

        { 

         totalCharCount += count; 

         ret += new String(readBuffer); 

         count = streamRead.Read(readBuffer, 0, 256); 

        } 

        ret = ret.Substring(0, totalCharCount); 


        return ret; 

       } 

       catch (Exception x) 

       { 

        return x.Message; 

       } 

回答