I have following method which accepts a text file and I am trying to upload this text file on the web service. I use a user name and a password. But I get an exception: "The remote server returned an error: (404) Not Found.". If I supply the user name and password again I get the same exception. What should I do to overcome this issue?
public static void UploadTextFileToWebService(string txtFile)
{
WebClient webClient = new WebClient();
string webAddress = null;
try
{
webAddress = @"https://www.myweb.org/mywebwebservices/dataupload.asmx";
webClient.Credentials = CredentialCache.DefaultCredentials;
WebRequest serverRequest = WebRequest.Create(webAddress);
WebResponse serverResponse;
serverResponse = serverRequest.GetResponse();
serverResponse.Close();
webClient.UploadFile(webAddress + txtFile, "PUT", txtFile);
webClient.Dispose();
webClient = null;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}