Why is file uploads through Silverlight 2 limited to .TXT files only?

I have a Silverlight 2 application that is sending a byte array to a Silverlight-enabled WCF service. However (if I don't try to load the .txt file) the service method is SaveFile()

never reached and I get the error: "The remote server returned an error: NotFound"

Am I missing something really obvious? Why can't I upload .doc files? Why only .txt?

UPDATE: I tried to attach a debugger for CLR exceptions, but it didn't help. I still don't see any errors other than 404. Here's my code:

in Page.xaml.cs:

OpenFileDialog dlg = new OpenFileDialog();

if (dlg.ShowDialog().Value)
{
  byte[] fileContent = new byte[dlg.File.Length];

  using (FileStream fs = dlg.File.OpenRead())
  {
    fs.Read(fileContent, 0, Convert.ToInt32(fs.Length));
    fs.Close();
  }

  Service1.Service1Client srv = new SL1.Service1.Service1Client();

  srv.SaveFileCompleted += (sender1, e1) =>
  {
    foo.Text = "Uploaded!";
  };

  srv.SaveFileAsync(dlg.File.Name, fileContent);
}

      

in Service1.svc.cs:

[OperationContract]
public string SaveFile(string fileName, byte[] fileContent)
{
  string ret = String.Empty;

  try
  {
    string target = @"c:\debug123\" + fileName;

    if (File.Exists(target))
    {
      File.Delete(target);
    }

    File.WriteAllBytes(target, fileContent);

    ret = "OK";
  }
  catch (Exception ex)
  {
    ret = ex.ToString();
  }

  return ret;
}

      

Does anyone see something wrong with this?

0


source to share


4 answers


FYI, I figured out my problem and solved this article . "By default, the largest message that can be sent to a service from a client is 8124 bytes." So I had to increase the limit using the bindings config settings.

But now my main problem is how to get the corresponding error message instead of 404. I will have to research this a little more, but hopefully someone else can come up with a good answer (unfortunately CLR exception breaking didn't help me) ...



UPDATE: After further reading the same article , I found that the WCF Service Utility included in the Windows SDK can help identify the underlying problem.

+2


source


I'm not sure what the specific problem is, but I can tell you that the downloads are definitely not limited to .txt files - I downloaded 10MB WMV files with no problem. Perhaps there is something with the service side encoding that is causing the problem?



+1


source


There is no such limitation.

Attach a debugger to the service and check which exception is thrown. To do this, you need to configure Visual Studio to throw exceptions when they are evaded (as opposed to unhandled ones). Do this in the Debug-> Exceptions dialog box by checking the box on the left in the Exclude Common Languages ​​row.

By attaching a debugger to the service (Debug-> Attach to process), you can see the real error. The NotFound error is a common error - the real error is only visible from the service side.

+1


source


0


source







All Articles