I have an application developed in C# for desktop which will access MySql Database in an online server. Since it is a shared database the client IP can't access the Database directly so i need to implement a proxy server which can accept the request from the client and after processing the business logic by using the Database it will return the result back to the client. The proxy will be acting as an intermediator. I haven't been able to think of a way to implement the proxy server to handle the request. Leaving the Proxy aside the other things are in place and running fine. Any other alternative is most welcome!!!!
Wouldn't it be better if your application just makes a HTTP-request to a page on your server, and the page itself executes the query and returns the result as json, xml, csv or whathaveyou? This way you avoid problems with users behind a firewall who can only use port 80, and it's easier for you to filter out malicious queries in your script before they reach the database.
Related
I am working on a web application in C#, ASP.NET, and .NET framework 4.5 with the use of WebSockets. In order to plan for scalability in the future, the application pool has the option for web gardens enabled to simulate multiple web servers on my single development machine.
The issue I am having is how to handle re-connects on the websocket side. When a new websocket session is initially created, the client browser can indirectly lock records in a SQL database. But when the connection is lost, my boss would like the browser to attempt to re-connect to the same instance of the websocket server session so it doesn't need to re-lock anything.
I don't know if something like this is possible because on re-connect the load balancer will "randomly" select which web server to handle the new connection. I was thinking of some hack to work around this but it isn't very clean:
Client opens initial websocket connection on Server A and locks a record.
Client temporarily loses internet connection and the websocket closes. (It is important to note that the server side will wait up to 60 seconds before it "disposes" itself; therefore, the SQL record will remain locked until the 60 seconds has elapsed).
Client internet connection is restored and reconnects to the website but this time on Server B.
Server B sees that this context was initially connected on Server A; therefore, transfers the session to Server A.
Server A checks the process id to see if it is running in the correct worker process (in the case of a web garden).
Server A has found the initial instance and handles the connection.
I tried Googling this question but it doesn't seem like a very common issue because I don't think most websocket web apps keep records locked for as long that my applications does (which is could be up to an hour).
Thanks in advance for all of your help!
Update 3/15/2016
I was hoping that the Server.TransferRequest would have been helpful however it doesn't seem to work for web sockets. Would anyone know of a way to best transfer a websocket context from one process to another?
First, you might want to re-examine why you're locking records for a long time and requiring a client to come back to the same server every time. That is not the usual type of high scale web architecture and perhaps you're just creating this need to reconnect to the identical server because of that requirement when maybe you should rethink how that is designed so that your application would work just fine no matter which host a user connects to.
That would certainly simplify scaling to large numbers of users and servers if you could remove that requirement. You can always then implement local caching and semi-sticky connections later as a performance enhancement, but only after you release the requirement to 100% of the time connect to the same host.
If you're going to stick with that requirement to always connect to the same host, then you will ultimately need some sort of sticky load balancing. There are a lot of different schemes. Some are driven by the networking infrastructure in front of your server, some are driven by your server and some are even client driven. They all have different tradeoffs. Here's a brief run-down of some of the schemes:
Hardware, networking load balancer. Here you have a fairly transparent mechanism by which a hardware load balancer (which is really just software running on a custom piece of hardware) sits in front of your web server farm and uses various techniques to make sure whatever server a given user is originally connected to it will get reconnected to on subsequent connections. This can be based on various schemes (IP address, cookie value, etc...) as the key to identifying a particular user and it typically has a number of possible configurations for how it can work.
Proxy load balancer. This is essentially an all software version of the hardware load balancer. Here a proxy sits in front of your server farm and directs connections to a particular server based on some algorithm (IP address, cookie value, etc...).
Server Redirect. Here an incoming connection is randomly assigned to a server. Upon connection the server figures out where the connection is supposed to be connected to an returns a 302 redirect to the actual host causing the client to reconnect to the proper server. This involves one less layer of infrastructure (no physical load balancers), but exposes the different server endpoints to the outside world which the first two options do not.
Client Selection Algorithm. Here the client is given knowledge of the various server endpoints and is coded with an algorithm for consistently selecting one for this user. It could be a hash of a userID that is then divided into the server bucket pool and the end result is that client ends up choosing a particular DNS name such as cl003.myserver.com which it then connects to. This choice requires the least work server-side so can be simpler to implement, but it requires changing the client code in order to modify the algorithm.
For an article on sticky load balancing for Amazon Web Services to give you an idea on how one mechanism works, you can read this: Elastic Load Balancing: Configure Sticky Sessions for Your Load Balancer.
Here's another article on how the nginx proxy is configured for sticky load balancing.
You can find lots of other articles with a Google search for "sticky load balancing".
A discussion of the pros/cons of the various schemes is the subject of a much longer discussion and some of it involves knowledge of more specific requirements and specific capabilities of your infrastructure.
I'm trying to make a login app.
I would like to know how the connectionString on app.config is made for an online connection and if I would need anything else to reach the database, being as I'm trying to go directly to the user table on that database and perform a check for the login (as I already made it happen with a local database)
Best Regards
Your online database, does that mean a database at a remote location?
I would advise against going directly to a remote database unless that database server is protected in a LAN environment with no outside public access. Public access would also be considered if users inside the LAN also have unregulated access to the remote server. In any thick click based application the typical architecture would be to go through a proxy source or set of WebServices to authorize and authenticate users. Direct access opens your SQL server up to remote attacks.
That being said the connection string to an SQL server (remotely) could be:
Standard User\Pass
Server=myRemoteServer;Database=myDataBase;User Id=myUsername;
Password=myPassword;
Now chances are there are firewalls between the remote database and your client APP protecting remote logins (as there should) and it is a good possiblity that SQL server has disabled remote logins. Read here for more http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx
I must point out again that this is a very bad idea and I would personally create a set of WCF WebServices to run on the server with the database. The WCF services would be responsible for connecting to the database to verify the credentials and return a structured datamodel.
WPF Applications are designed to work really well with the Async methods of WCF services and are very simple to setup. Using this model you can also setup more advanced layers of authentication using hashed token sets, implement SSL to block sniffing out the plain text, and keep your database protected from external access.
There are alot of examples on the web to connect to WCF services from a WPF application.
Please actually read my post before placing it on hold!!
Let me start by saying I've been searching for a solution all afternoon and so far I have seen plenty of examples for WCF but none that would do what I need.
I have developed an application in c# that will be installed on customer servers and accesses a sql server on the customer's local network. The application also has the ability to control network relays on the customer's local network and records the status of these in sql. I am trying to figure out a way to have the customer's server establish a connection to our datacenter and be able to issue commands back to the customer's server (retrieve datasets from sql, control the network relays, etc). I have found plenty of ways to have a client call classes on a server but have so far been unsuccessful in finding the reverse. One consideration was writing a web service as part of the application on the customer's server but need a way to establish this connection for customers with dynamic IP addresses and without having to publish through firewalls, etc.
Have you considered using
VPN - Virtual private network
or
Configuring a Port Forwarding redirect on the ADSL modem, and using a solution like www.noip.com ?
If I understand correctly you want to get information from the customer's database, which is behind a firewall and has no known static ip, in addition there might be several hundred customers so a dedicated VPN to the customer is not viable.
First of all: you should not contact the customer database directly. Databases are not designed for this scenario and would probably be left open to attack if exposed directly to the internet.
So you need a service on top of the database. There are two main options you can use for this service:
Polling service
The service is actually a client calling some web service on your network and asking for instructions.
Benefits: easy to implement and deploy.
Downsides: With polling there is always the cost-benefit of scalability/bandwidth use vs. speed of service. There are also some considerations in selecting the time to poll to prevent all the client polling at the same time.
The service is a tcp-server
This can be a usual web service (or RESTfull service) or some other service. The only difference is that it needs to advertise itself. For that you need to have a known directory server. When the service starts it then connects to the directory service and tells it the port it can be contacted on (the directory knows the ip from the connection). It will then need to periodically contact the directory to let it know it is still alive and so any change in IP is detected.
A client on your network would now query the directory to find the address of the client and connect directly to it to issue commands.
Benefit: Scalable and bandwidth efficient.
Downside: More difficult to implement. Requires firewall traversal solutions (UPNP or firewall exceptions).
I want to control application (in my case it is corelDraw) ,I know I should use it's application object and I do this, but the issue now is I want to do this in webservice,
so as far as I understand if I put this code which control the application in the web-service ,my code will try to control the corel application which is on the server not on the client :(
so any hint/advice how could I do this, and control the application on the client not server ?!!!
As you already noticed web service runs on server and only result is passed to client.
Well you have a few options to control client machine over web service... Here is one of possible scenarios.
1. create web service that will provide commands for client
2. create windows service (client) that will consume your web service commands
3. inside windows service then just execute those commands in appropriate manner
Well I have to say this is not the prefered way I would take to automate corelDraw, but if you insist on using webservice as command provider it will do the job.
You need to ask yourself what is the difference between client and a server. Can a client be a server? Can a server be a client?
You make your client with CorelDraw installed to accept web-service request, i.e. effectively make it a web-service server, and then carry on as normal.
Although I would say web-service is not the best way to control such complex application as CorelDraw. I'd look in some other ways of communication between peers, like lower level network communication that would not have overhead of HTTP.
I am looking to write an application that will take client data from a database, transfer it to our server application, manipulate that data and then pass it back to the client. I would like this to be as seamless as possible and as secure as possible. Also, the manipulation part of this could take several hours. The format of the data will be different for each client. To make the application as easy to maintain as possible, the simplest solution too.
What methods would people recommend for achieving this?
WCF will make your implementation easy. It looks like you are wanting to have the client -> server -> client communication asynchronous, since the server process can take hours, you don't want to block your client that long.
You probably want to define a server WCF service contract to allow the clients to load data to the server. You also want a client side WCF service contract that the server can use to send the results back when the processing is completed. OR you can have the server send a small message to the client WCF service telling it that "results are ready, come and get them when you are ready". You will need to coordinate this with some type of ID; the server tells the client to use this id when it wants to collect the results.
Have a look for duplex, asynchronous and peer-to-peer communication topics in WCF. There should be plenty of examples if you google around.
Please take a look at WCF framework of .NET 4.0.
1/backup the database in prod
2/download it,
3/restore in local
4/modify,
5/backup in local
6/upload
7/restore in prod
to download in https or sftp, with ip restriction
you can compress the database before download it too