Web API Missing on deployment - c#

So I have a C# MVC Web API and Web Application that is an all-in-one project. I've created something similar to this in the past but the Web Application and Web API were two different projects with two different URLs.
For example:
The Web Application would be hosted at mywebsite.com/webapp
The Web API would be hosted at mywebsite.com/webapi
Any time I wanted to call the Web API from the Web Application all I had to do is send an Ajax request using the URL mywebsite.com/webapi/api/getdata
However, with my current project it's all-in-one. So in testing I would simply call /api/getdata and it would work just fine in Visual Studio debug. But when I deploy this site for testing and actually host it all my API calls are met with HTTP 404 errors.
So how do I call the Web API when the Web API doesn't have it's own distinct URL?

In IIS I converted the folder to an application and then made sure to switch the calls from
mywebsite.com/api/getdata
to
mywebsite.com/myproject/api/getdata
and it's working now.
Credit to #mxmissile for pointing it out.

Related

ASP.NET Core Web API endpoint throwing HTTP 405 error after modifying Uri format

I have an Angular frontend and a backend in ASP.NET Core Web API. The Angular app calls the Web API using www.website.com/api/v1/FetchData which works fine.
This Web API application is set up as a website in IIS with specific app pool.
NEW CHANGE:
I added more Web APIs under the main website. Each is a separate Web API project in solution file.
In IIS wwwroot folder there is a main folder "webapp", each webapi is under a subfolder under it called webApi1, webApi2, webApi3. Under the Website in IIS, we added each subsite (Web API library) as a "Web Application".
So new set of URI for each nested Web APIs looks like this:
www.website.com/webApi1/api/v1/FetchData
www.website.com/webApi2/api/v1/FetchData
www.website.com/webApi3/api/v1/FetchData
Issue
Now when I hit the Angular app, the call goes up to IIS of the server hosting WebApi1. But we get HTTP 405 error. When I checked logs it contains "www.website.com/webApi1/api/v1/FetchData 405 0 1 1"
where 405 is HTTP Error and 3rd 1 is sc-win32-status which means "Incorrect Function".
For each API controller, we defined the same routing attribute. No changes in that:
[Route("api/v{version:apiVersion}/[controller]/[action]")]
What could be wrong? Please advice. I don't see any issues with code or the way IIS is set up. I also checked the HTTP Verbs and there is no issue. The FetchData endpoint is configured as POST call and we can see POST in the logs.

Host a Web application and Web API Project that Use IP Address on Two different Web Servers

Current Scenario that works well:
I have a .NET solution that contains 2 projects - Web Application and a Web API Project.
When I need to Publish - I am publishing Web Application first and then Web API project on the Web Server. I am using IP Address to Communicate from Web Application to Call Web API Controllers.
The client now needs this Application to be published to two different web servers that of course have different IPs.
How do I publish because I am using an IP address that is different for both the web servers?
Even if I use hostname/server name, I would get into the same issue of both being different.
Will you have 2 different databases?
I didnt not understand you clearly what is the problem here, if you host Web Application on serv1 and Web API on serv2, Web Application will use serv2 IP address to access the Web API, usualy Web API does not need to access to the Web application since is used just to store and revive data from someware but if u need to push something to the Web Application, Web API will use serv1 IP address to access.
If the WebApp is in angular/react then create the build from VS Code or whichever ide you are using.
If as WebApp you are using Razor/Mvc then remove all the references and then at every call instead of having the call directly have a web api call.
Web Api can be published independently if no references are attached to it.

ASPNET Web API application return error in client side

I want to develop a full stack web application using ASP.NET Web Api. Can I develop that using single ASP.NET Web API project, or else Do I want to develop a separate client application?
I have already developed a REST service Web Api application and runs well. But I cannot load the view files in the app. I tried to change the localhost ports in the same app. But I can give only one port.
Postman shows the data for the restful services. But client does not load. It gives a error like this.
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Views/Home/SupplierDetails.cshtml
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3429.0
You can create the front-end of your web application in ASP.NET, with the Web API operating alongside (in another controller) in the same web application. In fact, that's a great way to "dog food" your API to make sure it is functional and useful for developers.
By creating the Web API, you make your API available for other clients and consumers; and your ASP.NET Web Application can be one of those clients.

When Web API is called from same project is working fine. But when I call same API from another project in same machine, it is giving 405 method

First time when I created Web API project(MVC pattern) and I created few API controllers and called from html page(Ajax call),I am able to call all APIs and get the data.
But second time I've created two separate solutions one is asp.net Web API and another is MVC Web application.
Now I'm running both the projects in my machine and trying to call web APIs from MVC application, it's coming 405 method not allowed client side error.
Can anyone help me with this scenario.
Anything extra I need to configure in my server Web API to be called from different application?

How does calling a web service from a .net app work?

I added a web service as reference to a project and gave it name "days". But I don't actually understand how to work with it. Can someone show me the way how to get data from it?
In posh I get data from a web service this way:
$ws= New-WebServiceProxy -uri $xmld.Root.WebService.Address -credential $cred
$xml = $ws.getdays()
$xml
Have a look at
Walkthrough: Calling XML Web
Services from Windows Forms
Creating a .NET Web Service
Walkthrough: Accessing an XML Web
Service Using Visual Basic or Visual
C#
Fortunately, you don’t need to write a client application to test a web service because .NET includes a test web page that ASP.NET uses automatically when you request the URL of an .asmx file in a browser. This page uses reflection to read and show information about the web services, such as the names of the methods it provides.
To try the test page, request the xyz.asmx file of the web service in your browser. (In Visual Studio, you simply need to set this as the start page for your application and then run it.)

Categories