0

I have created Web application using asp.net MVC architecture. I have used Web API for getting data from database. Both Web application and Web API are in same project. I have not published Web API separately on IIS.

When I am debugging or running the application through Visual studio it works properly. I have used below code to get data from Web API URL

 TODOINfo[] lstToDoInfo = httpClient.GetAsync("http://localhost:65373/api/RESTApi").Result.Content.ReadAsAsync<TODOINfo[]>().Result;

In Above function I am passing url which consist of localhost plus fixed port number. Above code is working fine when running through in Visual studio.

I have published the same code on IIS by doing below changes.

TODOINfo[] lstToDoInfo = httpClient.GetAsync("http://" + sBaseUrl + "/api/RESTApi").Result.Content.ReadAsAsync<TODOINfo[]>().Result;

sBaseUrl value is "localhost".

After Browsing the application on internet explorer getting following error.

No MediaTypeFormatter is available to read an object of type 'TODOINfo[]' from content with media type 'text/html'.

Any information or suggestion regarding above problem is highly appreciate.

7
  • Do you mean that I have to deploy Web API on IIS. As I am new to IIS configuration. Please give the reference link for it. Commented Jun 22, 2016 at 16:21
  • I have not read completely, but I am pretty sure this will give you what you need: support.microsoft.com/en-us/kb/323972 let me know if you encounter further problems and I'll walk you through it, Later. Commented Jun 22, 2016 at 16:24
  • On second thought Because your API is in the same project, though, you are probably better off keeping it all under the same WebApp in IIS. but you will have to change the baseURL to whatever the host + site: Commented Jun 22, 2016 at 16:32
  • Thanks for the reference link. I will go through it. I just want to confirm that after publishing application from Visual studio still its need to configure it on IIS. Commented Jun 22, 2016 at 16:33
  • 1
    Thanks for the support. Its work for me.... :) Commented Jun 22, 2016 at 16:46

1 Answer 1

1

Try changing sBaseURL to "localhost/" +yourwebsite

another option would be to change: sBaseURL to: servername/yourwebsite

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.