HttpClient not sending the request to Web Api async get method





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I haven't used Web Api in a while and I am stuck with something that should be very simple.



I have an asynchronous get method in a Web Api controller:



public class SomeController : ApiController  
{
[HttpGet]
public async Task<IHttpActionResult> MyMethodAsync(Guid id)
{
//... doing something.
}
}


On my client application I am trying to call it like so:



using(var client = new HttpClient())
{
var result = client.GetAsync($"{url}/Some/MyMethodAsync/{Guid.NewGuid()}");
//I have tried making the above call with and without await
//since I saw in some other post that it is not needed.

//.... doing something else.

//This POST method does stop in the beak point I set inside of it.
var result2 = client.PostAsync($"{url}/Some/MyPostAsync", someContent);
}


The problem that I have is that it seems that the request is not even being sent to the Web Api since the break point that I am setting on MyMethodAsync has the warning that the symbols are not being loaded.



What really confuses me is that the next call is to a POST method on the same controller that when I call it the symbols load and its breakpoint gets hit.



Like I said, I am comming back to Web Api after a really long time and quite a few things are fuzzy in my mind. I only have the default route so, I do not know if I have to add more specific routes and if so, how to specify them.



As a side note I have two other GET methods that also have a Guid parameter. I have tried calling those with the same result.



Thank you for your help.



UPDATE: To make matters more confusing. If I run the application but instead of using the client I open a browser and enter the url exactly as the client would do it, the break point in the action gets hit. Right after that I try using the client and then it won't.










share|improve this question

























  • Did you try [HttpGet(“MyMethodAsync/{id}")]

    – Joe B
    Jan 3 at 5:42











  • @JoeB - I think that is the attribute for Asp .Net MVC because when I try to do that it won't compile telling me that the attribute's constructor has no parameters.

    – Sergio Romero
    Jan 3 at 5:58











  • If you have 2 projects same time(one for api, and other for presentation layer), please set different ports, and start 2 projects together.

    – isaeid
    Jan 3 at 6:17











  • Try client.GetAsync($"{url}/Some/MyMethodAsync?id={Guid.NewGuid()}")

    – Pranav Singh
    Jan 3 at 6:24




















1















I haven't used Web Api in a while and I am stuck with something that should be very simple.



I have an asynchronous get method in a Web Api controller:



public class SomeController : ApiController  
{
[HttpGet]
public async Task<IHttpActionResult> MyMethodAsync(Guid id)
{
//... doing something.
}
}


On my client application I am trying to call it like so:



using(var client = new HttpClient())
{
var result = client.GetAsync($"{url}/Some/MyMethodAsync/{Guid.NewGuid()}");
//I have tried making the above call with and without await
//since I saw in some other post that it is not needed.

//.... doing something else.

//This POST method does stop in the beak point I set inside of it.
var result2 = client.PostAsync($"{url}/Some/MyPostAsync", someContent);
}


The problem that I have is that it seems that the request is not even being sent to the Web Api since the break point that I am setting on MyMethodAsync has the warning that the symbols are not being loaded.



What really confuses me is that the next call is to a POST method on the same controller that when I call it the symbols load and its breakpoint gets hit.



Like I said, I am comming back to Web Api after a really long time and quite a few things are fuzzy in my mind. I only have the default route so, I do not know if I have to add more specific routes and if so, how to specify them.



As a side note I have two other GET methods that also have a Guid parameter. I have tried calling those with the same result.



Thank you for your help.



UPDATE: To make matters more confusing. If I run the application but instead of using the client I open a browser and enter the url exactly as the client would do it, the break point in the action gets hit. Right after that I try using the client and then it won't.










share|improve this question

























  • Did you try [HttpGet(“MyMethodAsync/{id}")]

    – Joe B
    Jan 3 at 5:42











  • @JoeB - I think that is the attribute for Asp .Net MVC because when I try to do that it won't compile telling me that the attribute's constructor has no parameters.

    – Sergio Romero
    Jan 3 at 5:58











  • If you have 2 projects same time(one for api, and other for presentation layer), please set different ports, and start 2 projects together.

    – isaeid
    Jan 3 at 6:17











  • Try client.GetAsync($"{url}/Some/MyMethodAsync?id={Guid.NewGuid()}")

    – Pranav Singh
    Jan 3 at 6:24
















1












1








1








I haven't used Web Api in a while and I am stuck with something that should be very simple.



I have an asynchronous get method in a Web Api controller:



public class SomeController : ApiController  
{
[HttpGet]
public async Task<IHttpActionResult> MyMethodAsync(Guid id)
{
//... doing something.
}
}


On my client application I am trying to call it like so:



using(var client = new HttpClient())
{
var result = client.GetAsync($"{url}/Some/MyMethodAsync/{Guid.NewGuid()}");
//I have tried making the above call with and without await
//since I saw in some other post that it is not needed.

//.... doing something else.

//This POST method does stop in the beak point I set inside of it.
var result2 = client.PostAsync($"{url}/Some/MyPostAsync", someContent);
}


The problem that I have is that it seems that the request is not even being sent to the Web Api since the break point that I am setting on MyMethodAsync has the warning that the symbols are not being loaded.



What really confuses me is that the next call is to a POST method on the same controller that when I call it the symbols load and its breakpoint gets hit.



Like I said, I am comming back to Web Api after a really long time and quite a few things are fuzzy in my mind. I only have the default route so, I do not know if I have to add more specific routes and if so, how to specify them.



As a side note I have two other GET methods that also have a Guid parameter. I have tried calling those with the same result.



Thank you for your help.



UPDATE: To make matters more confusing. If I run the application but instead of using the client I open a browser and enter the url exactly as the client would do it, the break point in the action gets hit. Right after that I try using the client and then it won't.










share|improve this question
















I haven't used Web Api in a while and I am stuck with something that should be very simple.



I have an asynchronous get method in a Web Api controller:



public class SomeController : ApiController  
{
[HttpGet]
public async Task<IHttpActionResult> MyMethodAsync(Guid id)
{
//... doing something.
}
}


On my client application I am trying to call it like so:



using(var client = new HttpClient())
{
var result = client.GetAsync($"{url}/Some/MyMethodAsync/{Guid.NewGuid()}");
//I have tried making the above call with and without await
//since I saw in some other post that it is not needed.

//.... doing something else.

//This POST method does stop in the beak point I set inside of it.
var result2 = client.PostAsync($"{url}/Some/MyPostAsync", someContent);
}


The problem that I have is that it seems that the request is not even being sent to the Web Api since the break point that I am setting on MyMethodAsync has the warning that the symbols are not being loaded.



What really confuses me is that the next call is to a POST method on the same controller that when I call it the symbols load and its breakpoint gets hit.



Like I said, I am comming back to Web Api after a really long time and quite a few things are fuzzy in my mind. I only have the default route so, I do not know if I have to add more specific routes and if so, how to specify them.



As a side note I have two other GET methods that also have a Guid parameter. I have tried calling those with the same result.



Thank you for your help.



UPDATE: To make matters more confusing. If I run the application but instead of using the client I open a browser and enter the url exactly as the client would do it, the break point in the action gets hit. Right after that I try using the client and then it won't.







c# asp.net-web-api2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 6:01







Sergio Romero

















asked Jan 3 at 5:07









Sergio RomeroSergio Romero

2,78273056




2,78273056













  • Did you try [HttpGet(“MyMethodAsync/{id}")]

    – Joe B
    Jan 3 at 5:42











  • @JoeB - I think that is the attribute for Asp .Net MVC because when I try to do that it won't compile telling me that the attribute's constructor has no parameters.

    – Sergio Romero
    Jan 3 at 5:58











  • If you have 2 projects same time(one for api, and other for presentation layer), please set different ports, and start 2 projects together.

    – isaeid
    Jan 3 at 6:17











  • Try client.GetAsync($"{url}/Some/MyMethodAsync?id={Guid.NewGuid()}")

    – Pranav Singh
    Jan 3 at 6:24





















  • Did you try [HttpGet(“MyMethodAsync/{id}")]

    – Joe B
    Jan 3 at 5:42











  • @JoeB - I think that is the attribute for Asp .Net MVC because when I try to do that it won't compile telling me that the attribute's constructor has no parameters.

    – Sergio Romero
    Jan 3 at 5:58











  • If you have 2 projects same time(one for api, and other for presentation layer), please set different ports, and start 2 projects together.

    – isaeid
    Jan 3 at 6:17











  • Try client.GetAsync($"{url}/Some/MyMethodAsync?id={Guid.NewGuid()}")

    – Pranav Singh
    Jan 3 at 6:24



















Did you try [HttpGet(“MyMethodAsync/{id}")]

– Joe B
Jan 3 at 5:42





Did you try [HttpGet(“MyMethodAsync/{id}")]

– Joe B
Jan 3 at 5:42













@JoeB - I think that is the attribute for Asp .Net MVC because when I try to do that it won't compile telling me that the attribute's constructor has no parameters.

– Sergio Romero
Jan 3 at 5:58





@JoeB - I think that is the attribute for Asp .Net MVC because when I try to do that it won't compile telling me that the attribute's constructor has no parameters.

– Sergio Romero
Jan 3 at 5:58













If you have 2 projects same time(one for api, and other for presentation layer), please set different ports, and start 2 projects together.

– isaeid
Jan 3 at 6:17





If you have 2 projects same time(one for api, and other for presentation layer), please set different ports, and start 2 projects together.

– isaeid
Jan 3 at 6:17













Try client.GetAsync($"{url}/Some/MyMethodAsync?id={Guid.NewGuid()}")

– Pranav Singh
Jan 3 at 6:24







Try client.GetAsync($"{url}/Some/MyMethodAsync?id={Guid.NewGuid()}")

– Pranav Singh
Jan 3 at 6:24














1 Answer
1






active

oldest

votes


















0














1. Open App_Start / WebApiConfig.cs



enter image description here



2. Add New Route



config.Routes.MapHttpRoute(
name: "NewRoute",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);


2.1. FULL Code



enter image description here



3. USE Action Name Attribute [ActionName("MyMethod1")]



    [ActionName("MyMethod1")]
[HttpGet]
public IHttpActionResult MyMethod1(Guid id)
{
return Ok<string>($" ok MyMethod1 and id= {id}");

}


4. Same for MyMethod2



    [ActionName("MyMethod2")]
[HttpGet]
public IHttpActionResult MyMethod2(Guid id)
{
return Ok<string>($" ok MyMethod2 and id= {id}");

}


Extra Note : For the symbols are not being delete error in visual studio




  • close visual studio

  • Delete WebApplication1bin

  • Delete WebApplication1obj

  • Open visual studio

  • build the solution
    enter image description here






share|improve this answer


























  • @SergioRomero do yo still need help ?

    – Mohamed Elrashid
    Jan 6 at 21:39












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016641%2fhttpclient-not-sending-the-request-to-web-api-async-get-method%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














1. Open App_Start / WebApiConfig.cs



enter image description here



2. Add New Route



config.Routes.MapHttpRoute(
name: "NewRoute",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);


2.1. FULL Code



enter image description here



3. USE Action Name Attribute [ActionName("MyMethod1")]



    [ActionName("MyMethod1")]
[HttpGet]
public IHttpActionResult MyMethod1(Guid id)
{
return Ok<string>($" ok MyMethod1 and id= {id}");

}


4. Same for MyMethod2



    [ActionName("MyMethod2")]
[HttpGet]
public IHttpActionResult MyMethod2(Guid id)
{
return Ok<string>($" ok MyMethod2 and id= {id}");

}


Extra Note : For the symbols are not being delete error in visual studio




  • close visual studio

  • Delete WebApplication1bin

  • Delete WebApplication1obj

  • Open visual studio

  • build the solution
    enter image description here






share|improve this answer


























  • @SergioRomero do yo still need help ?

    – Mohamed Elrashid
    Jan 6 at 21:39
















0














1. Open App_Start / WebApiConfig.cs



enter image description here



2. Add New Route



config.Routes.MapHttpRoute(
name: "NewRoute",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);


2.1. FULL Code



enter image description here



3. USE Action Name Attribute [ActionName("MyMethod1")]



    [ActionName("MyMethod1")]
[HttpGet]
public IHttpActionResult MyMethod1(Guid id)
{
return Ok<string>($" ok MyMethod1 and id= {id}");

}


4. Same for MyMethod2



    [ActionName("MyMethod2")]
[HttpGet]
public IHttpActionResult MyMethod2(Guid id)
{
return Ok<string>($" ok MyMethod2 and id= {id}");

}


Extra Note : For the symbols are not being delete error in visual studio




  • close visual studio

  • Delete WebApplication1bin

  • Delete WebApplication1obj

  • Open visual studio

  • build the solution
    enter image description here






share|improve this answer


























  • @SergioRomero do yo still need help ?

    – Mohamed Elrashid
    Jan 6 at 21:39














0












0








0







1. Open App_Start / WebApiConfig.cs



enter image description here



2. Add New Route



config.Routes.MapHttpRoute(
name: "NewRoute",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);


2.1. FULL Code



enter image description here



3. USE Action Name Attribute [ActionName("MyMethod1")]



    [ActionName("MyMethod1")]
[HttpGet]
public IHttpActionResult MyMethod1(Guid id)
{
return Ok<string>($" ok MyMethod1 and id= {id}");

}


4. Same for MyMethod2



    [ActionName("MyMethod2")]
[HttpGet]
public IHttpActionResult MyMethod2(Guid id)
{
return Ok<string>($" ok MyMethod2 and id= {id}");

}


Extra Note : For the symbols are not being delete error in visual studio




  • close visual studio

  • Delete WebApplication1bin

  • Delete WebApplication1obj

  • Open visual studio

  • build the solution
    enter image description here






share|improve this answer















1. Open App_Start / WebApiConfig.cs



enter image description here



2. Add New Route



config.Routes.MapHttpRoute(
name: "NewRoute",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);


2.1. FULL Code



enter image description here



3. USE Action Name Attribute [ActionName("MyMethod1")]



    [ActionName("MyMethod1")]
[HttpGet]
public IHttpActionResult MyMethod1(Guid id)
{
return Ok<string>($" ok MyMethod1 and id= {id}");

}


4. Same for MyMethod2



    [ActionName("MyMethod2")]
[HttpGet]
public IHttpActionResult MyMethod2(Guid id)
{
return Ok<string>($" ok MyMethod2 and id= {id}");

}


Extra Note : For the symbols are not being delete error in visual studio




  • close visual studio

  • Delete WebApplication1bin

  • Delete WebApplication1obj

  • Open visual studio

  • build the solution
    enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 3 at 6:34

























answered Jan 3 at 6:09









Mohamed ElrashidMohamed Elrashid

2,06511024




2,06511024













  • @SergioRomero do yo still need help ?

    – Mohamed Elrashid
    Jan 6 at 21:39



















  • @SergioRomero do yo still need help ?

    – Mohamed Elrashid
    Jan 6 at 21:39

















@SergioRomero do yo still need help ?

– Mohamed Elrashid
Jan 6 at 21:39





@SergioRomero do yo still need help ?

– Mohamed Elrashid
Jan 6 at 21:39




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016641%2fhttpclient-not-sending-the-request-to-web-api-async-get-method%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith