Why is MVC Web Api only reachable when started in debug mode? - c#

I am facing a strange problem on both my laptop and desktop computer.
In my solution I have an MVC 4 Web Api and the solution is started by Visual Studio 2013.
So If set the Web API project as startup project then When I type some url of the web api it hits the controller.
But if the startup folder is another project, like a website that consumes this web api, then the web api is just unreachable.
I even tried to hit the same url that works when web api is started in debug mode.
So, what could be wrong?

Most likely the issue is that web server is not running. Try hosting your web API in IIS with a fixed URL and port.
Or your try setting multiple start up projects like this:
In your Solution Explorer,
Select, Right click your solution.
On the Project menu, click Properties. The Solution Property Pages dialog box opens.
click Startup Project.
Click Multiple Startup Projects and set the project actions start.

Two possible ideas to try:
Left click on the WebApi project, and open the properties window (F4 for shortcut key) ensure Always Start When Debugging is set to true
When debugging your consumer application, right click on the WebApi Project, and click Debug > Start New Instance
If they don't work the best solution would be to host the WebApi application using IIS / IISExpress

I have found the actual problem.
I am running Windows 7 x64 and Visual Studio 2013.
I had to uncheck the Enable Edit and Continue checkbox under Tools->Options->Debugging.
Now I am using a single startup project in my solution and I can call the web api also when not in Debug mode.

Related

ASP.NET Core 3.1 Web Application can run in a console too?

I'm confused about the new ASP.NET Core Web Application option when creating a new application in Visual Studio 2019. I originally wanted to start off by creating a RESTful Service. I found YouTube videos on how to do this, and the way to do it is by selecting ASP.NET Core Web Application template, and then selecting the API template on the second window. When I run the app, it runs in a browser.
But when I look at the project properties, it shows Output Type = Console Application. The Debug tab of the Properties window shows that I can uncheck the option "Launch browser" and select Launch option to be Project. When I run it under these options, it runs in a Console window.
What am I actually doing here? Am I running this RESTful service in a host console without having to write a console host myself?
This is not really a web application. Am I correct in saying this? Even though my first selection is to choose ASP.NET Core Web Application template.
I'm a little confused about the name of the template.
Thanks in advance.

Where and what is built in C# Web API 2

After successfully following this introduction to Web API 2 (although unable to "run" by pressing f5) I am really confused as to what is built and what is run when you create a WebAPI2 project. The only way I was able to test if it was working was by right clicking the project and clicking View -> View in Browser. I can't seem to find any .exe in the build folder (the app does build fine) to run.
What exactly is built and what is required to run a WebAPI2 projecT?
Your only output in a web project are a bunch of DLL's and maybe some static files that you could be using in your project (see this link about ASP.NET Web Project Folder Structure) . You don't have a .exe or an executable file in this case. Your built app requires a web server in order to execute, and when you are developing a project you have some options. Check this link about Web Servers in Visual Studio.
In order to run your project pressing F5, check if your ASP.NET Web Api project is configured as startup project. Check this link about how to configure it.
If you are still having any issue trying to run your web application in Visual Studio, please provide us with more information about your problem or errors, so we can provide you a better answer.

Host and Debug Silverlight application through IIS

I've been new to silverlight applications and trying to figure out this issue for past few days.
I tried creation a silverlight application in VS 2012, there are two separate projects created,
With Xaml files where the actual content exists
The .Web project where the .xap file is created.
When I tried running this through VS with breakpoints in the first project through IE the breakpoints were connected quite well.
When I tried hosting this project on IIS and tried running it on IE, it worked. (I hosted the .Web project only)
While I tried browsing the silverlight app from IIS and attached the process to IE with type silverlight,x86 in VS with those breakpoints in project 1, I was unable to hit them.
Please help me to debug my silverlight app when I try to browse it from IIS.
I tried everything I could think of so far. A hint would really be helpful.
Thank you.
Phew, finally this is fixed. Everything was precisely as it was supposed to be, I just missed out on the flow that was necessary. Below is the approach to debug silverlight app through IIS
Create a new silverlight app in vs
build it and create a new website in iis
in website add the silverlight.web project
add breakpoints in silverlight app from the same path as hosted in iis
browse the aspx page of .web from iis
click on attach to process (while the aspx page in running in IE) and search for iexplorer with type silverlight,x86 and click attach. (Make sure you're running VS in admin mode).
Refresh the IE page, and voila you have what you want.

How to debug a web service in a C#/.NET solution from a web application

I have an application solution consisting of eight projects in C#/.NET with Web services.
One of the projects is of web services.
All the data is fetched through the web services in a Windows Forms application.
But while debugging my Windows application I am unable to debug the web services called for fetching the data in Visual Studio 2010.
How do I debug a web services project in a solution when data fetching events are fired?
Normally, when debugging in Visual Studio the selected StartUp project will be executed in debug mode. In your case you need to start and debug both the Web API project as well as the WinForms project. You can do that by right-clicking in the solution explorer and selecting Set StartUp Projects. A dialog box opens where you can select Multiple startup projects and then select which projects to start when debugging the solution.
Another option is to have a single StartUp project (the Web API project as this is a requirement for the other project to run). You can then right-click on the WinForms project in the solution explorer and select Debug -> Start new instance. You can do this multiple times to debug multiple instances of the same project.
Obviously, you can always attach the debugger to any running process and if your Web API is deployed using IIS it will already be running. Using the procedure outlined above Visual Studio will attach to the right worker process.
You should attach Visual Studio to the host process of your web service.
This process is usually the IIS worker process which name is w3wp.exe on IIS 6+ on Windows Server 2003, Vista , later.
To attach to this process, you can use Debug -> Attach to Process in visual studio. Inside the Attach to process dialog box Make sure you've checked the Show processes from all users and also when selected your process, make sure that Managed code is selected. To select managed code click Select... and check the Managed Code checkbox (V2.0 or V4.5,4.0 depends on your selection of framework)
You can debug the web service by attaching the VS debugger to a process as follows:
Debug > Attach to Process > Attach
You can browse the available service that you are looking for and attach.
You can attach to the process of your web service. In Visual Studio, click menu Debug → Attach to process.
This writing is 2019, solution is to attach to IISExpress. Debug -> Attach -> find iisExpress (not the tray) in the list, .

Debugging in VS2013 with WCF

Due to recent hardware failure, I've had to go back to an old laptop of mine. I newly installed VS2013 on Win8 and am finding a new behavior. Used to be, when I would debug one of my Winforms projects, the other included WCF application projects would automatically launch to the
http://localhost:42898
(etc) address. Now, with this new install of VS2013, I can't get the IIS Express versions to launch when I'm debugging my other projects.
Does anyone know of how to configure VS to automatically build and launch these ancillary web apps during debugging of winform apps?
You are looking for multiple startup projects. Right click on your solution and select Properties -> Startup Project -> Multiple Startup Projects:
Now when you hit F5 both your WCF service and WinForms applications will start in Debug mode.

Categories

Resources