TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ritu
1.4k
348
43.5k
consume web api without database
May 19 2021 2:37 PM
initally i have json file in which some get methods are defined and i don't have database and i want consume web api in asp.net core console application and read json file from json file and send data to database.
url which i have passes in main method (which is access through postman, impport the json file in postman and retrieved some GET methods).
so please help me in this code
how to consume web service and send data to database.
i have created ue_GDL_CustAddrs.cs which contains
public
class
ue_GDL_CustAddrs
{
public
string
Name {
get
;
set
; }
public
string
Addr1 {
get
;
set
; }
public
string
Addr2 {
get
;
set
; }
}
public
async
void
GET(
string
url)
{
//string result = string.Empty;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method =
"Get"
;
StreamReader reader;
try
{
HttpClient client =
new
HttpClient();
client.BaseAddress =
new
Uri(url);
client.DefaultRequestHeaders.Accept.Add(
new
MediaTypeWithQualityHeaderValue(
"application/json"
));
HttpResponseMessage response = client.GetAsync(
"https://csi10a.erpsl.inforcloudsuite.com/IDORequestService/ido/load/ue_GDL_CustAddrs"
).Result;
if
(response.IsSuccessStatusCode)
{
IEnumerable < ue_GDL_CustAddrs > Addr = response.Content.ReadAsAsync<IEnumerable<ue_GDL_CustAddrs>>().Result;
foreach
(var p
in
Addr)
{
Console.WriteLine(
"{0}\t{1};\t{2}"
, p.Name, p.Addr1, p.Addr2);
Console.ReadLine();
}
}
else
{
Console.WriteLine(
"{0} ({1})"
, (
int
)response.StatusCode, response.ReasonPhrase);
}
}
catch
(WebException ex)
{
WebResponse errorResponse = ex.Response;
using
(Stream responseStream = errorResponse.GetResponseStream())
{
reader =
new
StreamReader(responseStream, System.Text.Encoding.GetEncoding(
"utf-8"
));
String errorText = reader.ReadToEnd();
}
throw
;
}
}
i have send the url through main method but got an exception
One or more errors occurred. (Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[Englert_Ewarranty_QAD_Integration_Details.ue_GDL_CustAddrs]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'Items', line 2, position 10.)'
Reply
Answers (
2
)
how to add new row sum of column in excelsheet
Block by CORS POLICY