Reputation: 6406
I need to consume a web service. that webservice requires user authentication. When I try to add a reference to the web service I'm getting a error saying
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm="AXIS"'. The remote server returned an error: (401) Unauthorized. If the service is defined in the current solution, try building the solution and adding the service reference again.
Is there any way to get out of this error?
Upvotes: 3
Views: 1439
Reputation: 26199
You need to provide the Credentials
from your Code and also configure the clientCredentialType
Type and realm
from you app.config
file.
follow below steps:
Step1 :
add following set of tags in your app.config
file.
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" proxyCredentialType="None"
realm="AXIS" />
Step 2:
from your code before accessing the API you need to provide credentials(UserName and Password).
//you must be having below two lines of code already in your code.
Assuming your WebServiceCLient as ProjectWebServiceClient
ProjectWebServiceClient client;
client = new ProjectWebServiceClient();
//Add following two lines of code in your source code:
client.ClientCredentials.UserName.UserName = "yourusername";
client.ClientCredentials.UserName.Password = "yourpassword";
Upvotes: 4