Hello All,
I need help of people who have knowledge of ASP.NET Web API integration with ASP.Net MVC
I have built an ASP.NET Web API web service and it is working nicely in that when I
type the URI in the address bar of my browser as shown below and hit the enter key,
it returns all the info in the browser in JSON format:
http://localhost:52581/api/customer
So the next thing I did was try to consume the information from ASP.NET MVC using the
HTTPClient but instead of getting the information I expect ... I do not get any data back
, there is no error information either so I am at a lost as to what is happening as all I get
at the lower left corner of the browser is a message that says "Waiting for localhost..."
The ASP.NET MVC and ASP.NET Web API are in two separarate solutions but running on
on the same machine using two separate open instances of Microsoft Visual Studio Express
2013 for Web ... how do you think can I solve this problem? All advise appreciated.
1 public static List<Customer> GetAllCustomers() 2 { 3 HttpCall.RunAsync("http://localhost:52581/", "api/customer").Wait(); . . .
4 public static async Task RunAsync(string baseURI, string appendToBaseURI) 5 { 6 using (var client = new HttpClient()) 7 { 8 //Send HTTP requests 9 baseURI = baseURI.Trim(); 10 if (baseURI.Substring(baseURI.Length-1,1) != "/") 11 { 12 baseURI = baseURI + "/"; 13 } 14 client.BaseAddress = new Uri(baseURI); 15 client.DefaultRequestHeaders.Accept.Clear(); 16 client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 17 HttpResponseMessage responseMessage = await client.GetAsync(appendToBaseURI); 18 if (responseMessage.IsSuccessStatusCode)
Line #3 above calls Lines 4 through 17 ... at line 17 it seems to be stuck at processing
and never gets to line 18 at all as described above.
I do not have big data that could cause such a wait as all the data I have that a call
to http://localhost:52581/api/customer directly from the address bar of browser as described
in paragraph above is shown below and as you can see it is very small:
[{"$id":"1","Authorizes":[{"$id":"2","Customer":{"$ref":"1"},"ID":1,"UserName":"PapaH","Password":"secretivePass","CustomerID":1},{"$id":"3","Customer":{"$ref":"1"},"ID":2,"UserName":"PapaM","Password":"anotherOne","CustomerID":1}],"Boats":[{"$id":"4","Customer":{"$ref":"1"},"ID":1,"RegistrationNumber":"1234","Manufacturer":"Acme
Corp.","ModelYear":2000,"Length":30,"CustomerID":1},{"$id":"5","Customer":{"$ref":"1"},"ID":2,"RegistrationNumber":"4456","Manufacturer":"Velra Enterprises","ModelYear":2001,"Length":32,"CustomerID":1}],"Leases":[{"$id":"6","Customer":{"$ref":"1"},"LeaseType":{"$id":"7","Leases":[{"$ref":"6"}],"ID":2,"Name":"Quarterly","StandardRateAmount":450.00},"Slip":{"$id":"8","Dock":{"$id":"9","Location":{"$id":"10","Docks":[{"$ref":"9"}],"ID":2,"Name":"Calgary"},"Slips":[{"$ref":"8"},{"$id":"11","Dock":{"$ref":"9"},"Leases":[],"ID":2,"Width":97,"Length":35,"DockID":1}],"ID":1,"Name":"Dock
# 1","LocationId":2,"WaterService":true,"ElectricalService":true},"Leases":[{"$ref":"6"},{"$id":"12","Customer":{"$ref":"1"},"LeaseType":{"$id":"13","Leases":[{"$ref":"12"}],"ID":3,"Name":"Semi-Annual","StandardRateAmount":700.00},"Slip":{"$ref":"8"},"ID":2,"StartDate":"2013-05-24T00:00:00","EndDate":"2014-05-08T00:00:00","SlipID":1,"CustomerID":1,"LeaseTypeID":3}],"ID":1,"Width":10,"Length":25,"DockID":1},"ID":1,"StartDate":"2015-12-01T00:00:00","EndDate":"2016-01-27T00:00:00","SlipID":1,"CustomerID":1,"LeaseTypeID":2},{"$ref":"12"}],"ID":1,"FirstName":"Papa","LastName":"Hones","Phone":"403-476-2978","City":"Calgary"},{"$id":"14","Authorizes":[{"$id":"15","Customer":{"$ref":"14"},"ID":3,"UserName":"MatilSM","Password":"encryptThis","CustomerID":2}],"Boats":[],"Leases":[],"ID":2,"FirstName":"Matilde","LastName":"Santos","Phone":"522-498-4998","City":"Calgary"}]
Thanks in advance for all the help .. I really appreciate it.
Ric