Multi-Tier Application in .NET - c#

I am still learning .NET framework and I want to implement multi-tier application just for practice. My goal is to make application for hospitals.
Question: Is it good idea to implement multi-threaded server that accepts client requests via sockets -- Worker threads that deal with client requests and then route requests to data access layer?
This would be decent practice for thread management, but is this right way for my application? Is there any other solution to achieve this goal?
I'm thinking of implementing the multi-threaded server in java and client in .net?

Microsoft provides quite a bit of guidance for application architecture using the .NET platform.
I can recommend the Microsoft Architecture resources available here:
MSDN Architecture
Also, the 2nd edition of the Microsoft Application Architecture Guide is available here as a PDF:
MS AAG 2nd Edition

I think that your best option would be to write a WCF service application.
That is hosted in IIS, which does all of the connection and threading things for you, well mostly - you still have to write thread safe code.

Related

Combine .NET MVC website and Windows services

I am currently involved in a simple to medium complex IOT project. The main purpose of our application is gathering data from our devices and analyzing that data as well as calculating statistics.
On the server side we run a MVC application. Up until now we used Hangfire to schedule the calculations. Hangfire is an amazing tool for scheduling emails and other simple stuff, for more advanced things it's too slow. The calculations can take up a lot of time and are processor-intensive (we are trying to optimize them though), so we need to call them in a background task, a simple API call won't be enough.
I thought about splitting the application into multiple parts, the website, the core and a windows service.
The problem is, I never tried that before and I have no idea what the best practice is to achieve that kind of thing. I searched for examples and articles, but all I found were suggestions to use Hangfire and/or Quartz.NET.
Does anyone have any resources on what the best practice is to build a MVC application, a Windows service and how they could communicate (probably through a queue)? What is the best practice in such a situation?
Although there may be many different possible ways to connect a site with a windows service, I'd probably chose one of the following two, based on your statements:
Direct communication
One way of letting your site send data to your backend windows service would be to use WCF. The service would expose an endpoint. For simplicity's sake this could be a basicHttpBinding or a netTcpBinding. The choice should be made based on your specific requirements; if the data is small then basicHttp may be "sufficient".
The advantage of this approach is that there's relatively little overhead needed: You'll just have to setup the windows service (which you'll have to do anyway) and open a port for the WCF binding. The site acts as client, the service as server. There's nothing special with it, just because the client being a MVC site. You can take almost any WCF tutorial as a starting point.
Note that instead of WCF you could use another technology like .NET Remoting or even sockets just as well. Personally, I often use WCF because I'm quite used to it, but this choice is pretty opinion based.
Queued communication
If reliability and integrity is crucial for your project, then using a queue might be a good idea. Again: depending on your needs, there may come diffeent products into consideration. If you don't need much monitoring and out-of-the-box management goodies, then even a very simplistic technology like MSMQ may be sufficient.
If your demands to the aforementioned points are more relevant, then maybe you should look for something else. Just recently I got in touch with Service Bus for Windows Server (SBWS). It's the Azure Service Bus's little brother which can be used on premises locally on your windows server. The nice thing about it is, that it comes at no extra charge as it's already licensed with your windows server licence.
As with the first point: MSMQ and SBWS are just two examples. There may be a lot of other products like NServiceBus, ZeroMQ or others usable, you name it.

How to communicate between Windows Services

I have 2 windows services that I created using C#.
I would like one of the services to call a function in the second windows service.
How should I do it?
EDIT:
The issue is That I have to application that running ( I don't need them to be Rather service Process is good too) but I need this 2 application to communicate, this 2 application are on the same server,
Sure. There are a bunch of IPC mechanisms you could use. Remoting, TCP/HTTP Listeners, etc.
Does either service provide functionality that might be useful outside of the other service?
See this thread for more ideas:
IPC Mechanisms in C# - Usage and Best Practices
EDIT:
As Davide Piras pointed out, if WCF is available for you to use, then consider using it. It will simplify life. The WCF configuration files are sometimes a pain to wield, but there's a nice tool for that too:
http://msdn.microsoft.com/en-us/library/ms732009.aspx
Are the services on the same box? Do you have .NET 4? Highly recommend using the fastest mode possible, memory-mapped files.
If they're on the same box, but you don't have .NET 4, or are in a homogenous Microsoft Windows network, named pipes could work. More to the point, I'd use WCF over a named pipe.
I found all the other answers correct but a little too much complicated (WCF is a big deal) and not scalable (memory and named pipes will only work on the same sever). I suggest you DotNetMQ messaging system. It's easy to use and deploy and let's you communicate even between processes running on different servers.

Non-enterprise uses for WCF?

I'm interested in gaining a better understanding of WCF.
Of course, I can read books and tutorials about it, but it seems that a better way would be to actually come up with some project idea (either open-source or a startup) which would actually benefit from using WCF, and then build it using WCF.
What are your ideas for small-scale projects which might benefit from WCF?
I'm not sure it is really a matter of scale that drives a decision to use WCF. If a learning project is all you are interested in, then take a normal idea for a project, and turn the entire data access layer into WCF calls.
This should give you a fair understanding of all the little nooks and crannies of WCF, and allow you to fail in a controlled manner. That way you can make decisions in the future about when are where it is best to apply a service boundary using WCF.
As was already mentioned, anything to do with the web can benefit tremendously from WCF. Heck, you could build a pure JavaScript and HTML 5 application using WCF without ever touching ASP.Net.
A hosted service that a mobile device (such as a WP7 or iPhone) could connect with to retrieve data
WCF is great for setting up non-ASPX endpoints for Ajax clients. See for example this article. There are many more out there.
Any project involving .NET and communication is likely to benefit from WCF. WCF is the replacement for ASMX web services and for .NET Remoting. There's no one particular type of application that it is suited for. For instance, it's not like it's suitable for Enterprise applications but not for small ones.
WCF data contracts are very easy and handy for storing application configuration, settings and state. Write a library/application to take care of serialisation and editing.

Creating MMC Snap-Ins for console application and windows service

Hi guys I need to have a standard management gui ( look and feel ) and lately I've been looking into mmc. Msdn and other free tutorials provides the installation and simple implementation of a snap in.
I'm confused right now on how I can integrate it with my production applications( console and windows service ). Do I need to set a communication protocol for my snap in and other applications? I'm thinking of doing some classic remoting or via wcf for the communication protocol but not pretty sure if that should be my road map.
What I needed is a sample demo or tutorial that implements a snap-in communicating with a working console application or a windows service. If anyone can give some pointers on how to do it or some real life implementation is very much appreciated.
MMC does not dictate how you talk to your code. It is only the presentation layer. You can do pretty much anything you like (as long as you are well behaved in terms of not blocking the UI thread), you can do network calls, ADSI, RPC, WCF, COM, Win32,....
We using the ironring C# library instead of the mmc3 c# support; it is more stable (and works with older mmc)

Best and Easiest Method for inter-process communication in large project

What is the best and easiest method that can be used for inter-process communication in a very large project?
My requirement is to communicate between a normal Windows Forms Application and Windows Services.
Methods that are easy to maintain and implement are preferred.
Thanks
From the tags I understand that we are talking about .NET. Perhaps you should try Microsoft WCF. It unifies this issue, abstracting specific inter-process (inter-service) communication technology from actual code. So generally you'll design and write the interfaces that your processes will use to talk to each other and then you'll configure a specific communication technology in XML config file. That is, you have rather clear separation between "what do the processes talk about" and "how is this communication implemented specifically".
WCF supports SOAP, TCP\IP communication, MSMQ etc., you processes can be IIS-hosted web-services, usual Windows services, console applications etc. - all this under unified framework. I think, this is exactly what you are looking for.
It really depends on the project as there are a large number of methods.
This may depend on where the different portions of the project run (They could run on different servers, or different technology stacks altogether.).
The most common method is probably web services. Although these come with an overhead, so it may be worth looking at a simple interface API via a DLL.
Whatever you do it should probably be thought about and designed carefully, considering security and performance, and how you will extend or modify it in the future.
Not necessarily the best or the easiest....
In the .NET world try MSMQ or IBM MQ message queue middle ware.
If the communication is mostly 1-way, then consider using WCF services, which are both good and easy if you let the code generators in Visual Studio do most of the work for you.

Categories