开发者

WCF Service sends a .txt or .xls but not a .gz (Zipped file)

开发者 https://www.devze.com 2023-03-28 22:39 出处:网络
I have a WCF service up and running which saves a file to my server. I have tested this by sending a .txt file and a .xls file. The size of the .xls file is 90kb.

I have a WCF service up and running which saves a file to my server. I have tested this by sending a .txt file and a .xls file. The size of the .xls file is 90kb.

Now I have a zipped file .gz that is only 70KB in size but when trying to complete this operation I get

The remote server returned an unexpected response: (400)

Bad Request.

When I have tried to search for this Bad Request most results lead to the fact that a large file is being sent and that I need to change the settings in the config file.

This is not the reason in my case as the .gz file is smaller than the .xls file!

Does anyone have any idea why this type of file cannot be sent the same as a text or Excel file???

Edit: Code Added

Here is the method to call the service

        string name = "New Doc";
        string file = @"C:/Users/Admin/Desktop/fileZipped.gz";           
        string ext = file.Split('.')[1]; 

        Stream stream = File.OpenRead(file);
        byte[] bytes = n开发者_开发知识库ew byte[stream.Length];
        stream.Read(bytes, 0, (int)stream.Length);
        stream.Close();

        var uploadFileServiceClient = new UploadFileServiceClient(); 
        uploadFileServiceClient.UploadFile(name, bytes, ext);

And here is my service:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]    
public class UploadFileService : IUploadFileService
{
    public bool UploadFile(string name, byte[] bytes, string extension)
    {
        string importDir = ConfigurationSettings.AppSettings["UploadFileDir"];
        if (String.IsNullOrEmpty(importDir))
            return false;

        if (!Directory.Exists(importDir))
            return false;

        string outputFile = Path.Combine(importDir, Guid.NewGuid() + "." + extension);
        string filename = outputFile.Split('\\')[2]; 

        using (StreamWriter sw = new StreamWriter(outputFile))
        {
            sw.WriteLine(bytes);
            sw.Flush();
            sw.Close();
        }
           return true;
    }
}

Like I say it works for text or Excel files.


IF there is no "filtering proxy" inbetween:

We had something similar and the solution turned out to setup the MIME type on client+server accordingly...

0

精彩评论

暂无评论...
验证码 换一张
取 消