I want to consume REST Web API using Console application, I have done with that. I am seeing most of the ASP.Net (But I dont need this example)
I need only console application example with passing Windows credentials and getting response.
Only GET method, I am going to use.
I am not sure how to pass the Windows credentials (User name and Password). The Service side they have added my User name and Pssword to use Windows authentication.
But I want to use Windows authentication - I need to use ServiceID and Password to connect to the Services.and get the data.
ServiceID: Domain\SNSVRSystem
Pwd: Password123
I need to pass this and get connected to the SErvice and retrive the data.
Please help, if anyone done with same example.
Prabakaran AnnaduraiPosted Jul 23, 2021, 5:01 PM
Hi, thanks for your reply.
This method is not worked out and I used the Network Credentials to tackle this.
Thanks a lot for your suggestions...
I have another issue by deserializing the OData contect values.
My REST API response data is as below.
{"@Odata.context": https \ /\ /testlab.mydomain.com\ /api\ /$metadata#ELMNT_REF_DATA",
"value":[ {"elem_name": "Aluminium" ,"elem_id": "E101","make_date": "2020-09-12","sts_code": "O"},
{"elem_name": "Copper" ,"elem_id": "E102","make_date": "2019-09-12","sts_code": "C"},
{"elem_name": "Silver" ,"elem_id": "E103","make_date": "2018-09-12","sts_code": "C"}
]}
I want to deserialize this with my ElementMapping class.
I am using NewtonJson class and jusing the below code, but getting null values, please let me know.
var response = httpClient.GetAsync(apiUSRI).Result.Content.ReadAsStringAsync();
var value = JsonConvert.DeserializeObject(response.Result);
I have class and mentioned decoaration as like below.
Please do send if any options we can do...
Public class ElementMapping
{
[JsonProperty("OData.value")]
public string elem_name {get(),set()}
public string elem_id {get(),set()}
public string sts_cd {get(),set()}
}
Public class RouteMapping
{
[JsonProperty("OData.Context")]
public string context {get(), set()}
public List Elements {get;set}
}
Arnab MukherjeePosted Jul 16, 2021, 6:58 AM
Please try the code given below,
You can check the given links also,
1. https://stackoverflow.com/questions/18347055/calling-a-rest-api-with-username-and-password-how-to
2. https://stackoverflow.com/questions/26430045/how-to-pass-windows-authentication-credential-from-client-to-web-api-service