How to verify Azure Load Balancer? - c#

I want to be able to configure the Azure Load Balancer Emulator in such a way that two consecutive calls to the web app will always result in calls to different instances.
How am i able to perform that?
How can i verify that the load balancer is working as expected? Using the HttpContext.Current.Request.Url and seing if the endpoint port changes?
Thanks in advance

The default Load Balancer which are available to your Windows Azure Web and Worker roles are software load balancers and not so much configurable however they do work in Round Robin setting. If you want to test this behavior this is what you need to do:
Create two (or more) instances of your service with RDP access enabled so you can RDP to both instances
RDP to your both instances and run NETMON or any network monitor solution in it.
Now access your Windows Azure web application from your desktop
You need to understand that when a network connection is made from your desktop the connection is still alive based on network settings (default 60 seconds) so you need to wait until default timeout is passed to access your Windows Azure web application again.
When you will access your Windows Azure Web application again you can verify that seconds time the request went to next instance. BE sure to pass the connection timeout otherwise your request will be keep handled by same instance.
Note: If you dont want to use RDP, you sure can also create a test ASP.NET page to write some special code based on your specific instance which will show you that this page is specific to certain instance. The best way to do is to read the Instance ID as below:
int instanceID = RoleEnvironment.CurrentRoleInstance.Id;
If you want to have more control over Windows Azure Load Balancing, i would suggest using the Windows Azure Traffic Manager which will help you to route the traffic to your site via Round-Robin, Performance or backup based scenario. More info on using Traffis Manager is in this article.

Related

Xamarin Forms HttpClient decide between two severs which one of them is up/active/responding

The scenario is this. On the company network, api url is different and when accessed from the outside, it is different. So when the xamarin forms appliaction starts, i need to test which of the two servers is responding to check whether it is the local network or the app is connecter externally. This will be the deciding factor for which ser to use for all other requests. Please note that the server is php based
You could use James Montemagno's Connectivity plugin for this. You can check whether the device you are using is online and also use the IsRemoteReachable call to see if a server can be reached.
Also, ensure that all the proper rights required by the plugin are selected in the Android Manifest.

Update client windows service with cloud data

Users will be able to configure the printer/scanner on a web application.
So I've a windows service running on client machine that communicate to cloud db through API and get the printer/scanner details and configure them accordingly in local network.
The service is configured to run every 30 minutes. So when a user modifies a printer/scanner property using the web application, the update will be available in client machine only after windows service run once. So the maximum time delay will be 30 minutes as the windows service is configure to run every 30 minutes.
Windows service cannot invoke API frequently as there will be too much load on the web server and also the update doesn't happen often but when it happens, customer expects their local network printer/scanner to be updated immediately with new configuration.
So, the question here is how effectively I could update the cloud data to the local service so that they will be in sync as soon as possible.
Please share if there is any other way to achieve this.
I've heard about message queue/clickone but I am not sure how it could suit here

ASP.NET Cache Management

I have three applications running in three separate app pools. One of the applications is an administrative app that few people have privileged access to. One of the function the administrative app allows is creating downtime notices. So when a user goes into the administrative app and creates a downtime notice the other two apps are supposed to pick up on there being a new notice and display it on the login page.
The problem is that these notices are cached and being that each app is in a separate app pool the administrative app doesn't have any way to clear the downtime notices cache in the other two applications.
I'm trying to figure out a way around this. The only thing I can think of is to insert a record in the DB that denotes the cache needs to be cleared and the other two apps will check the DB when loading the login page. Does anyone have another approach that might work a little cleaner?
*Side note, this is more widespread than just the downtime notices, but I just used this as an example.
EDIT
Restarting the app pools is not feasible as it will most likely kill background threads.
If I understand correctly, you're basically trying to send a message from the administrative app to other apps. Maybe you should consider creating WCF service on these apps that could be called from the administrative application. That is a standard way to communicate between different apps if you don't want to use e.g. shared medium such a database and it doesn't force you to use polling model.
Another way to look at this is that this is basically an inter-application messaging problem, which has a number of libraries already out there that could help you solve it. RabbitMQ comes to mind for this. It has a C# client all ready to go. MSMQ is another potential technology, and one that already comes with Windows - you just need to install it.
If it's database information you're caching, you might try your luck at setting up and SqlCacheDependency.
Otherwise, I would recommend not using the ASP.NET cache, and either find a 3rd party solution that uses a distributed caching scheme, that way all applications are using one cache, instead of 3 separate ones.
I'm not saying this is the best answer or even the right answer, its just what I did.
I have a series of ecommerce websites on separate servers and data centers that rely on pulling catalog data from a central backoffice website location and then caches them locally. In my first iteration of this I simply used GET requests that the central location could ping the corresponding consuming website to initiate its own cache refresh routine. I used SSL on each of the eCommerce servers as I already had that setup and could then have the backoffice web app send credentials via SSL GET to initiate the refresh securely.
At a later stage, we found it more efficient to use sockets instead on the backoffice where each consuming website would be a client and listen for changes in the data. The backoffice website could then communicate to its corresponding website when a particular account change and then communicate this very specifically. This approach is much more granular and we could update in small bits as needed as opposed to a large chunked update but this was definitely more complicated than our first try.

Web and windows forms application using same db issues

We have got a web application and a windows forms application. The web application contains a download link to download this forms application.
This forms application will check the client machine privileges and drive space etc. and will update the values to a global database using some webservice calls.
So the web application will continuously checking the global database for the status ie how much checking has been completed by the forms application.
So as soon as the download popup appears for the forms application to download, the web application will start to check the status. But if a user cancels the download or if a user close the forms application, then in these cases how the web application can stop checking for status.
But in my case the web application will always check for the status change , even if the client cancels the download or closes the forms application. So how to avoid this?
I think a timeout is your only real option here. Basically the web side will only check for a certain amount of time before giving up. Your status table in your database should include a "last update timestamp" field. If the status is not "complete", and the current time is greater than that timestamp by X seconds, the webserver assumes the process has timed out.
You could try to have some thing like a switch as part of a record or some thing in the Database, so the very next time your web app tries to read lets say the bit field it would know that it should stop checking. You could control this bit field as ON & OFF via your forms application. Then your web application you can setup a polling mechnism that checks the db every so often before timing itself off all together based on the bit field or if not been done then aftera period of time.
Having said that your forms application would need to be able to call the outside world where your db is some where located and update it, it can be done many ways, web service call, http, ect...
Update:
I apologies for the delay in replying but did you understand what I said? If your winforms application can call your web service then it can tell it to store a flag field some where like a record in the db for example that your web-application is polling and checking and then by setting that flag field your web-application would know to stop doing any thing with that record, item.
As you mentioned you are worried about:
User clicking cancel on download:
In this scenario you would not set the checking of your record by your web-application unless the user has downloaded and run your win-forms application for the first time, so dont start checking upon dowload of the win-forms application but start checking once for the first time the user has opened it, you can do this upon start of the winforms application by setting the flag field from your winforms app by calling your web-service. You will need a polling mechanism on top of this every so often, like a service.
When the user closes the winforms application
In this case you would upon termination/close of your winforms app call your web service and set the flag field not to check that record, item any more.
You will need polling in any case as I am thinking you will have many users and hence you will need to monitor the db for incoming messages from your winforms app. Also please be aware as some users are behind firewalls, limited security permissions on their machines and on private networks and your winforms app may not always be able to call your web service.
Hope that helped.

When do we use windows service?

Are there situations that we should use a windows service ?
I am building a client-server project (c#) and the server supposed to work alone without any user so someone advised me to use a windows service to run the server, is this right ? or there are a better solutions ?
Windows services are normally used when an application needs to continuously run. For example if they need to:
Wait for incoming requests. (Like through remoting or wcf)
Monitor a queue, file system etc.
If a program just needs to run periodically, like once a day. It is normally easier to create a scheduled task.
In your situation I would use a service for the following reasons:
You don't need to have a session running. This is good for security, and also reduces overhead on the server.
You get some of the managment commands built in for free
Start
Stop
Pause
Continue
You can handle server events such as shutdown.
Windows service can start running as soon as the machine is powered up, which makes ideal for running as a server, http server for example. No one is required to login.
You should create a Windows Service to run code in the background, without user interaction.
For example, a Windows Service will run even if no-one is logged on.
Any server that accepts connections (such as a mail, web, or FTP server) should usually be a Windows Service.
Well, a Windows Service provides a full framework for your application to work and to remain active while you want it to, so I think its ok.
Windows services are the right thing to use for something that should run all of the time, whether or not a user is logged in.
If you need something to run without an active user logged in, you need to use a windows service.
When you need the application to start running even when no one has physically logged into the machine, which is common with server machines, a service is a good candidate in this case. Especially because the service can be configured to auto start, which means the service will start when the machine is rebooted withut human intervention.
If however you are wanting to host web services (WCF) while a service is an option, you might consider hosting in IIS, this relieves you of writing the actual hosting code etc.

Categories

Resources