views:

50

answers:

1

I made my program according to example [1] that was made for .NET framework 2, but I converted it to .NET framework 3.5. How should I modify this code to make it working? How can I debug server side? Server side seems to work when I manually insert parameters to url, so problem must be in client side code.

private void UploadFile(string fileName, System.IO.Stream data)
{
    UriBuilder ub = new UriBuilder("http://localhost:59491/receiver.ashx");
    ub.Query = string.Format("filename={0}", fileName);

    WebClient c = new WebClient();
    c.OpenWriteCompleted += (sender, e) =>
    {
        PushData(data, e.Result);
        e.Result.Close();
        data.Close();
    };
    c.OpenWriteAsync(ub.Uri);
}

private void PushData(System.IO.Stream input, System.IO.Stream output)
{
    byte[] buffer = new byte[4096];
    int bytesRead;

    while ((bytesRead = input.Read(buffer, 0, buffer.Length)) != 0)
    {
        output.Write(buffer, 0, bytesRead);
    }
}

[1] http://www.c-sharpcorner.com/UploadFile/nipuntomar/FileUploadsilverlight03182009030537AM/FileUploadsilverlight.aspx

A: 

My initial take is the port specifier. On that sample, he has the request URI specifically set to port 3840, but he never shows modifying settings to force the web server to use that port when hosting the handler. make sure that the request URI is using the same port that you do when accessing the handler manually from a browser.

EDIT: I think this must be it, I just recreated the sample in a new project in VS2008 using the newest frameworks and everything works correctly, once I get the port set right.

As for debugging the server, if you're hosting the server half of the project out of visual studio (which you would be if you follow that guy on CSharpCorner sample), you should already be debugging the server component, just put a breakpoint in the server codebehind.

David Hay