EasyNetQ with asp.net web api as subscriber - asp.net-web-api

I have to implement a asp.net web api which acts as a subscriber to rabbitMQ. The windows service is going to publish message to the web api services. There will be more than one instance of web api running on production enviornment. I am not sure how to open up the subscriber channel on web api and keep it open untill the IIS restarts. There will be one publisher and several consumer.
Can anyone please guide with some sample code to start with?
Any help will hugely appreciated

Generally RabbitMQ subscriptions don't work well with IIS hosted applications because you have no control over when the application is running. IIS will recycle, stop and start the app as it sees fit.
If you must do it, open the connection to RabbitMQ and start subscribing when the application starts, in Global.asax.cs for example, and make sure to dispose of everything properly when it closes.
You are far better off building a windows service for the subscription and either writing to a shared store that the IIS hosted web service can access, or alternatively self-hosting the API inside the windows service.

Related

SignalR with Service Fabric Stateless Web API

Got some info from this related question: Using SignalR with Azure Service Fabric
Quote in quote from that comment history:
"After deploying this application, you can see that some calls to signalR fails and Some succeeds...."
Just want to know if anybody had similar implementation (signalR with Web API...).
And I don't want to set instance count 1 for the stateless Web API.
You can configure LoadBalancer that is used by Service Fabric to persist session. This will result in particular client ending up always in the same node.
You can do it by accessing LoadBalancer assigned to service fabric cluster in azure portal. Then go to "Load balancing rules", select rule that is responsible for signalR port and set "Session persistence" to "Client IP". This can also be done from PowerShell or ARM template.

Web is external and client side application, how to make ajax call to reach internal App Server

We have this architecture:
Web Server: Web Application is deployed (html, javascript, css)
Application Server: WebApi is deployed
Problem is , I cannot make ajax request to reach Application Server because its behind firewall.
The Web Application is supposed to be used publicly to the internet users.
What changes should we do to make it work?
Should we move our Web Application to Application Server? But how would this be accessible on internet.
Thanks in advance for suggestions/advice.
You're going to have to put an exception in the firewall for the address of your web server... that way your web server can access the API but nothing else can (well, not quite nothing else - other stuff on that web server can but that can easily be solved by having your web app hosted on it's own/dedicated web server).
If your Web Application makes direct calls to the Web API endpoint (e.g. is a single page application that use a client-side javascript framework like AngularJS and/or it uses AJAX calls to your application server address), there is no way for your clients to access your API if you do not allow public access to your application server.
That's because your client resides inside your users web browsers.
You have to allow incoming connections to your Application Server through internet in your firewall.
Well, it all depends on how you look at things and how distributed your application should be (criteria like load, security).
In general, Web API might be just one more client (from your applications server perspective).
On the other hand, in robust/distributed system, you would have Web API only as an endpoint (controllers, mappers and things like that) that your mobile/ajax clients send requests to and then Web API communicates to Application server (where your business logic is).
Having Web API communicate to DB directly is not a good idea because as you add clients to application server (mvc, web api, services, etc...) then you have as many db access points as you have clients. So, its a code maintenance problem plus a problem of your view tier being aware of DB.
Ideally, you need Application server as a tier where all your business logic is and its the one that all your clients target (mvc web app, web api, desktop, services, etc...) and that is the one that should communicate to your DAL. Also, then you can set firewall rules on your application server to allow incoming traffic from trusted sources (your other servers) instead from the whole internet (ajax).

should back end service for windows phone push notificatin always be a cloud application?

I want to develop an application that makes use of MSPN service. Is it necessary that my backend service be a cloud service
There would be no way to determine if a service is a cloud service or not (without being anti-competitive), so you should be able to use any web service, whether it is implemented using a cloud service such as Azure or not - as I understand it, for certification, it would have to be a web service, and not rely on something being installed on a PC on a private network.
No you dont need it to be a Cloud-Service, you can even implement your Push-Service in PHP or similar. But that has Limits, it cannot run periodically a Script or sth like that. All Push-Notifications have to be send manually.
To do this you need 2 Core-Components(In my example in PHP).
You have a Page on which the Phone-Application can register his MSPN Push-Uri, which then is stored into the Database.
A Page which takes the Uri(s) and then sends the Push-Notification to them

Windows azure project architecture

I am new to windows azure plateform i want to ask a very basic question. I am doing a project on windows azure and due to some concurrency problems i want also my Browser GUI to be in the cloud which will call the web services which are also deployed in the cloud.
Just need to ask that is it possible that i will also put my GUI in the cloud and i have some URL which i will hit so that my GUI will appear in the users browser...
I want my architecture some what like that
Sorry for the drawing but i am in very hurry
Your web browser would be on the user's desktop, and make a HTTP request to a web application/site that is hosted in Windows Azure. For instance, an ASP.NET MVC web site that makes a service call to a WCF service, that then retrieves data from a SQL Azure database. One way to do this would be to create a single hosted service that contains:
Web Role (to host your ASP.NET site)
WCF Web Role (to host your WCF service)
SQL Azure (for your database)
I think the web GUI you mentioned would be like an agent, it will connect to the real websit and render the content for you. If this is true I would like to say in theroy it's possible, but in practice it will be very difficult, since what you want to do is a web based web browser. You might need to handle HTML, CSS and JS, etc.. But if it's just a web ui that render your data from your service that is fine. So back to your question, when you said the "browser gui", if it's a desktop application, you cannot run it on the cloud; if it's a website then yes you can and your proposal looks fine.
Hope my feedback helps.

wcf windows service interaction

I have a windows service in which i host a wcf service.
What is the best approach to control the windows service via the wcf service? I already created the interfaces for the wcf service, but I have no idea how to interact with the windows service's classes and functions.
just to check that I'm understanding your problem correctly - you want to run a wcf service, so you create a windows service to host it, and you want your desktop client to be able to control the windows service (that's hosting the wcf service) by talking to the wcf service?
If that's the case, what is it that you're trying to do with the windows service? In some of the work I've done, I've set up the server such that there's the windows service hosting all the wcf services I want to run, and in order to interact with that windows service remotely (e.g. starting/stopping/restarting) I have another service running on the server (usually baked into the Amazon instance image so it's running on every new server that gets brought up) which my remote client can talk to instead. That way I have a means to trigger a service restart on all my servers without having to manually connect/remote desktop to each server. Of course, the second wcf service is secured by some means so it can't be exploited easily.
Is that the sort of thing you're looking to do?

Resources