I have added a web reference of a web service which url starts with https. And trying to call by the following C# code
testwebservices.BasicHttpBinding_GDataService webservice = new testwebservices.BasicHttpBinding_GDataService ();
Uri uri = new Uri(webservice.Url);
CredentialCache cache = new CredentialCache();
cache.Add(uri, "Negotiate", new NetworkCredential("username", "password", "domainName"));
webservice.Credentials = cache;
var response = webservice.GetMethods();
return response;
I am getting the following error
The request failed with HTTP status 401: Unauthorized.
I guess the reason is "BasicHttpSecurityMode has not been set as Transport" (which is possible if i add as service reference). I could not find any way to set that. Or this cannot be not achievable? This is a VS.Net 2005 project,
Updated: I have also add the following but still having the same error
webservice.UseDefaultCredentials = true
var response = webservice.GetMethods();
working version : The following code started to work. Thanks to @user469104
testwebservices.BasicHttpBinding_GDataService webservice = new testwebservices.BasicHttpBinding_GDataService ();
webservice.Credentials = new NetworkCredential("username", "password");
var response = webservice.GetMethods();