Publishing multiple web services to the same Azure VM - c#

Short story:
Can I publish more than one WCF web service to a single Azure VM? When I publish one, it appears to "overwrite" the other (I can use the new one but old one stops working).
Longer Story:
I have a web service which I published to an Azure VM and it's been working well. I recently started building another web service as another project in the same solution as the original web service. However, it doesn't seem that I can host more than one web service on the same Azure VM.
Let's say I publish service A and test it to make sure it works. Then I publish service B, and that works too. However, that causes service A to stop working. If I republish service A then that causes service B to stop working.
This leads me to believe that you can only publish one WCF service to an Azure VM at a time, unless I'm doing something wrong?
I could combine them both into one service, but I really don't want to do that as the business logic and purpose is different for each one. Is my solution to have a second VM?

Related

Should a hosted service be used in an ASP.NET Core Web API project when that service has to run before requests are made?

I've added a hosted service to my ASP.NET Core Web API project:
services.AddSingleton<IHostedService, ScheduledProcessingService>();
However, Main() and Startup don't get hit until a request comes in. That means my hosted service doesn't start until then. When running locally, when I start the app, I have to make a call to the API controller (which I'd like not to have to do) in order for the hosted service to run.
If my hosted service has to process, regardless of whether a web request comes in, is it wrong to put that service in a Web API project? Should I create a separate project for it?
I could change some IIS settings, like in this post, but I want to make sure I'm doing what's right.
Unless someone provides more clarity, I think this is the answer:
It's hosted in IIS so it's just how it works. To overcome this, I think we'd have to set up some automatic ping, hangfire.io, or simply putting it in its own project that is just a service.
Another option would be to change these settings on the app pool:
.NET CLR version: v4.0 (instead of no managed code)
Start mode: always running
Idle time-out: 0
Another suggestion:
We use the app initialization feature in IIS to start and keep the services running.

Confusion about WCF Class library and WCF application hosting

I have a web site and would like to expose certain functionalities using WCF.
Before deciding which type of WCF project I need to use I wanted to compare the differences between WCF Class library and WCF application. I know this question has been asked many times and answered many times and the answers are usually about different hosting options each one offers but I wanted to try and see the differences, so this is what I tried:
Step 1 - In a same solution, I have created a WCF Service library project and created Client console app project, set the console app as a startup project, referenced the service library project from the client project
and in the client console app I could instantiate the service and can consume the service methods. I didn't even add a service reference to the client project.
Step 2 - In a same solution, I have created a WCF Service application project and created Client console app project, set the console app as a startup project, referenced the service application project from the client project
and in the client console app I could instantiate the service and can consume the service methods. I didn't even add a service reference to the client project.
On both steps after compiling the solutions I was able to copy the client app's exe and the service dll's to a different location and still be able to run the clients.
Based on this little excercie I am confused about the hosting part. It seems wether I use WCF Class library or WCF application type I get the same result.
This is just like using multiple projects in a solution, you reference one from another and use the methods, there must be something I am missing which highlights the differences between the two and highlights the benefits of using WCF, also in the past I remember I had to add a service reference to the clients apps in order to consume the service, why is this not the case here?
Thanks
1) Running a wcf service application allows you to provide communication into a single application, where you have a single instance of a thing you want to provide access to. Maybe this is a game, or a chat room without an external state engine or datastore. This is useful for providing diagnostic information about an application you might have written for example. I used this to provide external control for an industrial robot that I wanted to provide remote control access for.
That is to say, that you write an application, it has a function. You want to expose part of that functionality to remote applications. You do this by adding a WCF endpoint to your existing application, so your application itself is controlling the WCF hosting elements, lifecycle of the endpoint etc.
2) Running a WCF Service is for when you've got an external data store, or your service is stateless. A translation service, lookup service and web page requests fall into this category.
With a service class, you're saying here is this service, this thing that provides a function. It isn't tied to the lifecycle of another application or process and is typically hosted by IIS. IIS manages when the class is loaded and run based on the requests that come into it. These services have no internal persistence and rely on an external datastore, or are, by nature, stateless (think of a postcode lookup, or a calculator service)
It sounds like you're actually adding the projects as references, rather than connecting to them as services. That is to say, that the consuming application is actually loading the service as an assembly (in the same application/ memory space) rather than as a separate application/ service that your application then uses WCF to communicate with.
The WCF Service Application template can be used to create WCF services with a hosting website created within the project
The WCF Service Library template can be used to create WCF services that are hosted by the WCF Service Host, and these can be tested using the WCF service Test Client.
the biggest advantage of using a standalone library (apart from decoupling the logic) is that you can easily migrate your service, i.e. host it in another application or another type of application. E.g., let's say you're hosting your service using IIS - you can easily move your service to a standalone application, etc.

Calling a locally hosted web service

I have a web service on a virtual development machine. This - as you would expect - works fine and all of my web methods are called and return as expected. Now I wish to call this web service from my base machine but I'm not sure of how to go about doing this.
What is the correct procedure to carry out the above?
you need to deploy the web services on IIS, you can do it in multiple ways one by using publishing utility

WCF Service behaves differently when installed

I have written a WCF service which acts as a data access layer for my client applications.
The service loads and calls api from a managed assembly which I have referenced in my service project. A windows service is hosting my WCF service. Also I have implemented a wix installer to install my service. the communication is going to be only WCF-WCF
Now the problem is when I run the service from Visual studio then all the api's are working as expected but when I install my service then, api's don't throw exception but doesn't return expected result. To solve this problem I tried following things
1)Tried basicHttpBinding, wsHttpBinding and netTcpBinding
2)Changed the service log on setting as admin
Can someone point out the problem here? I tried lot of things suggested in different sites but nothing was helpful till now. Please let me know if you need more information.

Why Host WCF Service in Worker Role

In the process of building my first AZURE based application using WCF services I have stumbled across a number of examples where people show how one can host a WCF Service inside a Worker Role.
Such as in these articles:
http://www.codeproject.com/Articles/188464/Host-WCF-Services-in-an-Azure-Worker-Role
http://code.msdn.microsoft.com/windowsazure/CSAzureWCFServices-20c7d9c5
Very simple question, can someone please explain what use case would require hosting a WCF service in a worker role? What are the motivation/advantages of doing this?
Hosting a WCF service inside of a WebRole implies that it is hosted within IIS. Some folks prefer to not have the footprint of IIS mess with their ServiceHost and host the service directly. They have more control over how the communication with their service is done without IIS in the middle.
Also, when shrink-wrapping the packaged solution for customers, it is simpler to create an installer package without trying to rely on IIS infrastructure that customers may or may not have properly deployed/configured.
HTH

Categories

Resources