When I work with a web service in Visual Studio and I'm using a web reference, the WCF web service project is automatically started as soon as I start the client application. Interestingly, this does not change when I remove the web reference.
Is there a setting in Visual Studio to get this behaviour, without actually referencing the service? (I'm working with a WebChannelFactory.)
In the solution's properties, under Common Properties, Startup Project, you can choose Multiple startup projects and select Start as the action for both the service and the consumer.
Related
I know this is probably something really stupid, but I've been searching google for 2 hours to figure this out.
I have a new test Azure app that I would like to debug in Visual Studio. If I set the startup project to the Web Role (MVC) project, I can hit breakpoints in VS, but it's not running in the emulator so all of my Azure calls fail.
If I set the startup project to the Cloud project, the emulator starts, then Visual Studio ends debugging and my web role is never launched.
What am I missing here? How do I launch my web page and still have access to the emulator?
(Side note.. why isn't there a Visual Studio 2012 tag??)
Although this doesn't answer your question directly, I always make sure that my projects run outside of the emulator. If for nothing else, this just greatly improves the efficiency of your development.
To avoid the issue of the Azure calls failing, one very basic practice you can use is to use a Dependency Injection framework (such as Unity or others) and create a LocalConfigurationManager and a AzureConfigurationManager which both implement some interface like IConfigurationManager, then if your code needs to ask Azure for an instance number, or config setting, etc... the LocalConfigurationManager can just return a hard coded number/setting, and the real AzureConfigurationManager will actually call Azure.
The trick is to use the Web.Debug.Config and Web.Prod.Config files (or perhaps just use the #IF DEBUG C# precompiler statement) to change the implementation depending on the build config.
I have just created a Azure project with an MVC Web Role and I was able to hit a breakpoint in a controller action without any issues. Some things to check:
Do you have a WebRole.cs file in your MVC project containing a class derived from RoleEntryPoint?
Is there a node in the Roles folder of the Azure project representing your MVC project?
When you run the Azure project does the Compute and Storage emulator icon show up in the Notification Area of the taskbar?
Does the ServiceDefinition.csdef file in your Azure project contain a Web Role node with an attribute matching your MVC project name?
WebRole name="MvcWebRole1" vmsize="Small"
As a quick test try creating a new Azure project with a MVC Web Role, add a controller with a single action that returns a view and put a breakpoint in there. Then set your Azure project as the "Startup Project". If everything is working correctly you should hit the breakpoint when you debug the Azure project.
I un-installed and re-installed all my Azure SDK's, to no avail.
This link
Debugging Azure: Error attaching the debugger to the IIS worker proccess
told me where to look for the error that was causing it to fail, which led me to this link:
http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/07fe087e-4ac3-4c4f-bd62-4fccff4afd45
The ACL on the Windows Azure registry entries were not in "canonical order".
All you have to do is fix that and this error goes away.
These are the steps I took:
1.) regedit, navigate to HKLM\Software\Microsoft\Windows\Windows Azure
2.) Right-click, choose "Permissions". You will get a warning that the
security information is incorrect and you get a button labelled "Re-Order".
Click this and the security information then shows up as normal.
3.) Follow the same steps for the Windows Azure AppFabric and Windows Azure Emulator
registry entries in the list after the Windows Azure entry.
Problem Solved!
Note that I found the key under HKLM\Software\Microsoft\Windows Azure, not under Windows\Windows Azure.
I have a solution with a WebAPI project and a VS Test project.
My tests make calls to the API using RestSharp via a Url rather than instantiating the controller itself and injecting things (context etc).
My question, is there a way to tell the test project to launch the web project via IIS Express when a test run begins? Currently I just run two instances of VS, one with the web projected with debugging started and the other running the test package
If you are trying to debug both the test and the service, consider doing this
Launch to debug your Web service in Visual Studio.
Click Debug -> Detach All. IIS Express will keep running.
Set a break point and start Debuging your Unit Test.
(Skip this if you don't need to debug the web service) Click Debug -> Attach to Process. Find iisexpress.exe and attach.
However, you lose Edit and Continue on your web service which was detached.
I wouldn't recommend using the network to unit test Web API. You open yourself up to potential flakiness in the test and you end up testing a whole lot more than the service itself.
But if you really must do so, maybe to test that your client can exchange information with the API, then I'd suggest you look into self-hosting the service:
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/self-host-a-web-api
Self-hosting lets you start up a server for Web API with just a few lines of code and you could have your tests start up this server in the right places. In most cases, this should behave the same as having your service hosted in IIS Express. But there are some important distinctions. For example, you won't be able to use some System.Web concepts you may be used to (like HttpContext.Current).
Update:
I've written a blog post about testing Web API services that might help -
https://learn.microsoft.com/en-us/archive/blogs/youssefm/writing-tests-for-an-asp-net-web-api-service
Hope that helps.
I know this is an old post but I was just faced with this issue. I can provide a more detailed response if / when anyone reads this.
In short.. I created a console app referencing the unit test assembly and via reflection and a simple menu system you can run any one of your tests.
I then set multiple startup projects to be the Web project and the console project.
I can then F5 and debug both the unit test and the Web project from within the same session. No attaching to a process of multiple solutions needed.
Running your web service or site in release non-debug by CTRL-F5 makes it run independent from Visual Studio and you are free to run your Tests from inside VS
I know that this is late but I use this solution:
Start two instances of Visual Studios. Start debugging the API in one VS and then debug the test in another.
I want to self-host a WCF service in a console application for debugging that lives in my hosting layer. I also have a WPF application that needs to call this WCF service. However, I am unable to Add Service Reference to the console project from the WPF project. What do I do in this scenario? This is easy to do with IIS self-host, just add a .svc file and have it point to the WCF service, but how to do this with console host?
First run the console app and ensure that the service is running.
Then go to AddServiceReference in visual studio and follow your intuition
One alternative to using "add service reference" is to generate a client using SvcUtil. Just fire up the service hosted in your console app, and execute a command in the Visual Studio command prompt with a signature somehwat like this (all on one command line):
svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config
http://localhost:8000/ServiceModelSamples/service
The final bit is the actual address of your service, and may differ based on your host.
I am getting the same problem as this:
Debugging w/ Attach to Process Starts ASP.NET Dev Server
Every time I attach to the web server, I get another asp.net development server, eventually ending up with more and more.
However I don't see the option described in my Properties page. I have Visual Studio 2010. All I have in the Properties is "Full Path" and "Opened URL".
EDIT: Note: they all have different port numbers
You created the application as a web site. If you create a new project (vs. web site), you will get the Project properties page that is described in the SO question you referenced.
I have created a WCF service in Visual Studio 2010 along with some supporting assemblies. I have also created a test project which contains multiple unit tests for the service and the supporting assemblies. Right now I have them all in one solution with the Test project having a service reference (http) to the WCF service.
If I debug the WCF service and select "Run checked tests" in a Test List I created, I can debug the WCF service without a problem. Note: I cannot select Debug Checked Tests while debugging the WCF service. (Because the IDE is already debugging?)
If I open the Test project in another instance of VS 2010, debug the WCF service and then select "Debug Checked Tests" - I can debug both my tests and the WCF service.
However - I would like to (and my question is) be able to debug my tests and my service in a single IDE. Is this possible?
I choose to host the wcf service in the same test process. So the test (maybe in the setup fixture) creates and opens the service host and at the end of the test, it closes/stops the service host. This will make debugging a breeze.
Are you running the WCF service in Cassini? If so, you should be fine, provided you have a service reference to the project from the calling code. It steps right through.
Hmm... at least it does in 2008, and I assume it does in 2010. I haven't tried it yet for 2k10; I'll go have a go at it and be back with a report.
Edit: Yep, it does.