views:

375

answers:

1

Hello everyone,

Here is my code at both client side and server side. My code is simple, just upload a file to an ASP.Net web site.

My client code throws exception when it works on Vista (x64, Enterprise, SP1), but works fine on Windows Server 2003.

Any ideas?

10.10.12.162 is my server address.

[Code] Client:

   static void Main(string[] args)
    {
        Console.Write("\nPlease enter the URI to post data to : ");
        String uriString = Console.ReadLine();

        WebClient myWebClient = new WebClient();

        Console.WriteLine("\nPlease enter the fully qualified path of the file to be uploaded to the URI");
        string fileName = Console.ReadLine();
        Console.WriteLine("Uploading {0} to {1} ...", fileName, uriString);

        DateTime begin = DateTime.Now;

        byte[] responseArray = null;
        try
        {
            responseArray = myWebClient.UploadFile(uriString, fileName);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.ToString());
        }

        DateTime end = DateTime.Now;

        Console.WriteLine("Elapsed time is: {0}", (end - begin).TotalMilliseconds);
    }

Server:

public partial class FileUploadHandler : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (string f in Request.Files.AllKeys)
        {
            HttpPostedFile file = Request.Files[f];
            file.SaveAs("D:\\UploadFile\\UploadedFiles\\" + file.FileName);
        }
    }
}

Exception from client side:

Unable to connect to the remote server System.Net.WebException: Unable to connect to the remote server ---> System.Net. Sockets.SocketException: No connection could be made because the target machine actively refused it 10.10.12.162:1031 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre ss socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Sock et s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.WebClient.UploadFile(Uri address, String method, String fileNam e) at FileUploadClient.Program.Main(String[] args) in D:\UploadFile\FileUploadClient\Program.cs:line 30 [/Code]

regards, George

+1  A: 

There's nothing about that code which would alarm me too much.

Open a remote desktop on the machine that is causing you problems. Open a command line. Issue the command:

telnet 10.10.12.162 1031

Do you see a cursor, or does telnet give you an error that it cannot connect? If you get an error from telnet, you probably have a NIC issue/firewall issue/router issue/other connectivity issue unrelated to your code.

Dave Markle
Telnet failed. But I tried ping the host is success. Here is the error message. Any ideas? Connecting To 10.10.12.162 ...Could not open connection to the host, on port 1031: Connect failed
George2
I have tried when I publish the ASP.Net project at server side to IIS and using port 80, everything is fine, but when pressing F5 to run in Visual Studio, there is such error. Any ideas?
George2
Well, the telnet error tells you that something is blocking that port at the network level, or there is no server listening on that port. You'll want to check your firewall and server settings on your 10.10.12.162 machine.
Dave Markle
Dave, firewall is off on server side. My server is Windows Server 2003 x64, anuthing else to check? Thanks.
George2
Some new findings.The port 1031 is the VSTS's internal web server address port number -- i.e. when I press F5 in VSTS for the ASP.Net project.When publish the ASP.Net project to IIS using port 80, everything is ok, but when pressing F5 to run in VSTS, there is such error. Any ideas?
George2
Sounds like you have a local Windows Firewall or other security software/setting blocking VSTS's random-ishly assigned port number. Go into your project and tell Visual Studio to use a fixed port number which you know is unblocked.
Dave Markle
Hi Dave, I worked on "Go into your project and tell Visual Studio to use a fixed port number which you know is unblocked" for quite some time. But can not find a configuration item in VSTS about this. Do you know where to set this?
George2
If you're in VS 2008, right-click your web applicaton project's icon and click "Properties". Select the "Web" tab from the left, and under the "Servers" section select the "Specific Port" radio button.
Dave Markle