[Solved] asp.net web api c# interface dataprovider

In your interface you have it defined as Task<IEnumerable<TabMain>> Gettabs(); but you implement it like this public async Task<IEnumerable<TabMain>> GetTabs() C# is a case sensitive language, so you need to either change your implementation method name or your interface method name. I would change the interface method name to GetTabs to go with the standard … Read more

[Solved] Task is getting the wrong value

I fixed it by changing api to var response = await client.GetProtectedAsync<ProductsCollectionPagingResponse>($”{_baseUrl}/api/plans/query={query}/page={page}”); from var response = await client.GetProtectedAsync<ProductsCollectionPagingResponse>($”{_baseUrl}/api/plans?query={query}&page={page}”); 1 solved Task is getting the wrong value

[Solved] C# WebAPI return JSON data

This is an example how to return json response from webapi controller public class UserController : ApiController { /// <summary> /// Get all Persons /// </summary> /// <returns></returns> [HttpGet] // GET: api/User/GetAll [Route(“api/User/GetAll”)] public IHttpActionResult GetData() { return Ok(PersonDataAccess.Data); } /// <summary> /// Get Person By ID /// </summary> /// <param name=”id”>Person id </param> /// … Read more

[Solved] An unhandled exception occurred while processing the request in cosmos db and asp.net core

The stack trace points to a NotFound in OperationType Read, ResourceType Collection. This means that the Uri that you are passing, is not pointing to a collection that exists in that account. You are creating the Uri using: UriFactory.CreateDocumentCollectionUri(_azureCosmosDbOptions.Value.DatabaseId, “catlogdb”) Check the value of _azureCosmosDbOptions.Value.DatabaseId and verify it is valid and it’s the one you … Read more

[Solved] What’s the difference between await (async) Task and await Task? [duplicate]

Case B is not async-await. If you have a thread, and this thread has to start a fairly lengthy process in which it has nothing to do but wait, usually because someone / something else performs the operation, then your thread could decide to do something else instead of waiting for the operation to finish. … Read more

[Solved] Parameter with hyphen in Web API 2

try this for url …./api/books?author-id=3&genre-id=5 . It works for all net versions [HttpGet] public async Task<IHttpActionResult> GetBooks() { var parameters = GetBooksParameters(HttpContext); // … } [NonAction] private BooksParameters GetBooksParameters(HttpContext httpContext) { var parameters = new BooksParameters(); var queryString = httpContext.Request.QueryString.Value; foreach (string item in queryString.Split(‘&’)) { string[] parts = item.Replace(“?”, “”).Split(‘=’); switch (parts[0]) { case … Read more

[Solved] HttpClient what and for what? [closed]

This should give you a start: private Order SendOrderRequest(Models.OrderTest model) { Uri uri = new Uri(model.BaseUrl + “order”); HttpClient client = new HttpClient(); client.BaseAddress = uri; var mediaType = new MediaTypeHeaderValue(“application/json”); var jsonFormatter = new JsonMediaTypeFormatter(); HttpContent content = new ObjectContent<Order>(model.Order, jsonFormatter); HttpResponseMessage responseMessage = client.PostAsync(uri, content).Result; return responseMessage.Content.ReadAsAsync(typeof(Supertext.API.POCO.Order)).Result as Supertext.API.POCO.Order; } It just posts … Read more

[Solved] Below c# code is not reading websites or webpage from given urls

This may help you below code contains for both to get and post data: public static string PostContent(this Uri url, string body, string contentType = null) { var request = WebRequest.Create(url); request.Method = “POST”; if (!string.IsNullOrEmpty(contentType)) request.ContentType = contentType; using (var requestStream = request.GetRequestStream()) { if (!string.IsNullOrEmpty(body)) using (var writer = new StreamWriter(requestStream)) { writer.Write(body); … Read more