ASP.Net Web and WCF projects in the same solution - asp.net

I am using Visual Studio 2010 and I am trying to create a solution containing an N tier architecture.
I have a project each for every tier
Common
DAL
Business //
Service // WCF
ServiceHost
Web
the projects are listed above are also called in the same order as well; so Web talks to Service tier, service tier talks to Business and business then talks to factory and factory project is responsible for talking to DB.
the issue I am having is to setup my projects in a way that before Web project is launched by pressing F5 - ServiceHost (which is just a self host console for WCF) should be started first so when Web calls for a service; it is up and running already.
Note: in PRD; Web and WCF will be hosted on different boxes altogether so this wont be an issue but for developing on Local machine - I need the above.
Interim Solution - I have excluded ServiceHost Project from the solution so it doesnt get launched with Web and I am running the ServiceHost executable externally from command line to get the Service up and running and then I am launching the Web project as normal using F5.
Can someone please tell me what do I have to do to achieve the above?

As Rajesh suggested, you set multiple projects to start in a multi-project solution. To do this, select DEBUG -> Set Startup Projects (or right-click on the solution and select Set Startup Projects... from the context menu.
This will give you a window that lists all your projects in the solution. Check the "Multiple startup projects" radio button, and set the Action column to "Start" or "Start without debugging" for each project you want to run. You can use the up and down arrows to specify the order.
If your web application requires the service to be available when it starts (i.e., the web site calls the service during it's initialization/startup), you may be better off doing as you are now (running the WCF service from the command line), otherwise this should get you where you want to be.
Attached is a screenshot (VS 2012) with a solution similar to the one you outlined above:

Related

Starting point of Azure WebApp

I opened a new .Net Framework WebApp and I am using it with Azure.
At the very first point, when I run the App from Visual Studio, it opens the browser and shows the default page:
I was looking for a "main" class or method but could not find one. I am wondering where does it start from? how this thing works?
If added a new method for which I want to run together with the WebApp, where should I call it from ?
I am wondering where does it start from? how this thing works?
This is about how does asp.net webapp run.When the application starts up, it runs Global.asax’s Application_Start() method. In this method, you can add Route objects to the static RouteTable.Routes collection. These will be inspected later when each request is received. Each Route object defines a URL pattern to be matched and the controller to be used in this case.
For more detail about how the Asp.net webapp run, you could refer to this article and this one.
If added a new method for which I want to run together with the WebApp, where should I call it from ?
When you publish to azure and add a new method in a controller, you could call it like yourappname.azurewebsites.net/Controllername/methodname. It mainly depend on your Rounte, you could refer to this article.
Azure App Service Web Apps is a service for hosting web applications, REST APIs, and mobile back ends. You can develop in your favorite language, be it .NET, .NET Core, Java, Ruby, Node.js, PHP, or Python. Applications run and scale with ease on Windows-based environments.
With App Service, you pay for the Azure compute resources you use. The compute resources you use is determined by the App Service plan that you run your Web Apps on.

Deploy Web-Api, Asp.net project and a Windows service in one msi project

Is it possible to deploy ;
1- a web-api project
2- a website written in Asp.net
3- a WCF service as windows service
in one msi file using/in Windows Web Installer Project (preferably) or in Wix ?
Yes, it is possible using WiX. I maintain an open source project called IsWiX that even makes it somewhat easy. See:
Create and Package a Windows Service using IsWiX
IsWiX Web Site Demo
The concept behind IsWiX is project templates (scaffolding) and graphical designers that give you a project structure and most heavy lifting for your WiX MSI project. The template already contains examples of IIS configuration that merely need to be uncommented out. If you need a Web API and a Web Site you'll have to clone that part of the code and make a few adjustments. For example a static website typically won't be a web application where a web-api will be. Then you'll use the services designer to define the windows service. The fact that the service hosts a WCF endpoint really doesn't matter.
For that matter, one of the really cool things about WCF is it's possible to eliminate your dependencies on IIS. I've seen solutions using this with no dependency on IIS and this really makes creating installers a lot simpler.

How do I use my web reference in Visual Studio 2008

I've got a sample project that has several web services and uses them during run time. The application works as intended. The web references are can be see in the Solution Explorer under a folder called "Web References" with the list of web services as single files.
I'm trying to use these same Web Services in another solution but it's not working. I've added the Web Services to the solution and they have appeared under a folder called "Web_References". In addition, the list of web services under this appear with the extension .discomap and have 2 subfiles under them with the same name but with the extension .disco and .wsdl.
These are the only differences I can see. However, in the 2nd solution, Visual Studio cannot resolve the references to the classes from the web services (I'm using the same code as the first solution).
Does anyone know why the web references appear differently and why my 2nd solution is not allow me to use the web references that I've added?
TIA
Update: Following on from the comments, yes the 2nd one is a web site and the first appears to be a Windows Application using web services. Given it's a website, how do I use the web references?

.NET and webservices: how?

Im trying to make a webservice in ASP.NET and get the data in a Smart Device Application.
I have the standard HelloWorld webservice and i wanna get the data in my application, but when i try to add a web reference to my project, Visual Studio can't find any webservices running. If i start the WebService in the WebService project and copy/paste the url to the "Add WebReference" in the Application project, Visual Studio finds the Webservice and i can use the InttilSence to find the HelloWorld Method (WebServiceClass.HelloWorld()) in the WebService. But when i then run the Application project the complier gives an error saying that it can't connect to the WebService.
How do i do this? How do i access a webservice in an Application project? Every tutorial or book i have read about the subject doesn't tell anything about how the webservice should i run. In my world the webservice project should be running before i can access it from another project or am i wrong?
Consider reading Rick Strahl's Creating Web Services with .NET and Visual Studio.
From there, you'll get the basics. You can build and deploy your XML SOAP web service.
Then you'll need to have your application use that web service as a 'Web Reference'. Start by "Add Web Reference".
(source: usaepay.com)
First, you should publish the web service to some server (even your own local IIS) rather than using the Visual Studio web server.
Then in your application, point to the correct URL wherever you published it when adding the reference.
While this is a bit low-tech, couldn't you create a web requrest from the Smart Device Application to hit the webservice directly? That would be my suggestion.
An example would be using the "WebRequest" Class.
It sounds like when you try to access the Web Service from your app, the service is not running (possibly because you're only running it in the Cassini server?).
The fact that you were able to generate the Web Reference means that at some point, the service was running and was able to generate the helper classes by examining the service.
I would do as David Stratton suggests and publish it somewhere where it can run while you are developing the Smart Device app (like your local IIS).
You might also take the opportunity to wrap the service call with some error handling - maybe catch the specific exception being thrown (System.Net.WebException?)

Web Service vs. WCF - different objects when consumed

I'm new to the WCF, and I'm looking for some advice. In my web app I consumed a web service (R+Click on project - "Add Web Reference") and started coding. My web app is really big, so it was taking forever to compile each time I wanted to debug, so I built a stripped down WinForm using the same code.
In VS2008 there is no "Add Web Reference" option when using the 3.5 framework, so I just chose "Add Service Reference" and used the same url. The objects/methods that I now have access to are completely different when compared to the objects/methods in the web app after consuming this as a web service.
Is that normal? Is this somehow related to the WCF?
Thanks
You can still add web references.
Do
Add Service Refernce
Hit the "Advanaced" button on the bottom left
Hit "Add Web Reference" on the bottom left.
Yes this is related to WCF. When your project target is >= .NET 3.0 the Add Service Referemce option will be available which will use svcutil.exe to generate client classes, otherwise you will have the Add Web Reference option which uses wsdl.exe. WCF clients use different classes to call a web service and that's why you get different classes generated.

Resources