.Net MVC Server to Server communications - asp.net-mvc

I need to do some simple comms between two sites, including the case where the same website acts as both the client and server.
The client needs to call a server function with signature something like:
complexObject GetData( int, string)
I'm on c#, .Net MVC 4.5 and running on Windows 7 for dev and & Server 2008 for hosting. I'm looking at both Websockets and SignalR, but can't decide on suitability (I don't need javsacript support, it's purely client/server). There also seems to be limitations running Websockets below Windows server 2012, and on combining client & server in the same app/website ( I could remove that requirement if its a serious issue).
Any advice on the right way to go would be great.

You cannot use WebSocket in ASP.NET unless you are using Internet Information Server 8, so you would need Windows 8 or Windows 2012 server.
SignalR will fallback to SSE, ForeverFrame or LongPolling if you are not using IIS8. SSE is unidirectional from server to client, and does not work in IE.
You can host a WebSocket component in a worker role, that runs in the same domain but in different port. Running in the same domain, the WS connection will send the cookie during the HTTP negotiation, but you would have to work out how to associate the user identity.
You can use for example:
XSocket.NET: http://xsockets.net/
SuperSocket: http://superwebsocket.codeplex.com/
That said, you can still use other technologies for communicating from server to server, like a duplex WCF channel.
A Beginner's Guide to Duplex WCF
Duplex Service in WCF
Cheers.

Related

DataSnap Web server working in FASTCGI, is it possible?

I created a DataSnap web server in Delphi that works as ISAPI in a IIS server. Some parts are not thread-safe and I would like to move FASTCGI. Is it possible?
When you create the DataSnap server from the Wizard, the allowed kind of servers are displayed:
There is no direct FastCgi possibility.
The Stand-Alone server has stability issues, and Apache is not so well supported under Windows, so installing it as an ISAPI module is the best known solution...

How to trigger an event from a web server to client en Delphi?

From a Web Server running in Windows 2012, I would need to send messages to specific clients. These clients are Delphi applications, over 2000. Each message is for a specific client, no broadcast.
Which technology can I use? I am totally new on this issue.
I am seeing Websockets, SignalR (that is based in Websockets), MSMQ, RabbitMQ, ...
MSMQ: Seems a good solution. Cons: It only works in Windows. Maybe in a future, I need to add other platforms as clients.
RabbitMQ: It is also good,but I think that it provides too features for my scenario. Basically I only need to send messages from server to specific clients.
SignalR: I am confused. It seems basically for web browsers, not for client applications. It seems a simple solution.
Basically, I am looking a simple and basic solution that I can implement in Delphi to receive messages from a web server.
WebSocket (a HTTP upgrade) is a light-weight option and also available for Delphi clients:
WebSocket is designed to be implemented in web browsers and web
servers, but it can be used by any client or server application. The
WebSocket Protocol is an independent TCP-based protocol.
See WebSocket client implementations for Delphi
RabbitMQ and other solutions are useful for example if the client could be offline while the server wants to send the message. The message broker provides a store where the message will be waiting for the client, even if the server restarts. Also a message broker will reduce load on the HTTP server.

Should I port my WebBroker projects to Indy

Long ago I started some "web applications" using Delphi 2007 and WebBroker (TWebModule). At the time I assumed you needed a webserver such as Apache or Microsoft IIS in order to create any sort of website. Additionally I don't use most of the Apache features (except for Virtual Server so I can have multiple domains on a single ip address and SSL). So to me Apache is just an extra layer and makes makes debugging difficult.
Now enter Indy (TIdHTTPServer). If I understand correctly, Indy IS a webserver. So by using Indy I am no longer bound to use Apache or some other webserver. Is this correct?
Will I have any issues supporting the Virtual Servers in an Indy environment? And what about SSL. I have searched the literature and from what I can see it fully supports SSL certificates.
I am now in the process of porting some of my application from WebBroker to Indy. This mostly entails replacing within my code references of Request: TWebRequest with ARequestInfo: TIdHTTPRequestInfo and references to Response: TWebResponse with AResponseInfo: TIdHTTPResponseInfo.
Is there anyway to use the TWebModule architecture within Indy so that I don't need to do all of this rewriting?
Lastly is there anything else I need to be concerned with? My goal is to take Apache out of the loop.
Yes, you can use Indy's TidHTTPServer as a webserver, but it's much lower-level than IIS or Apache. There is no concept of virtual servers - this you would have to implement yourself.
Indy does support SSL as well via the OpenSSL dll's.
I imagine the biggest concerns you will have will be security related...there are millions and millions of sites running Apache or IIS and there are a ton of people devoted to finding flaws in those platforms, with a bunch of people fixing some of those flaws as they come up. Not so with Indy... there's one or two guys that respond on newsgroups to bugs that you discover. (One guy in particular, who will probably respond to your question here as well.)
Now, I use Indy HTTP server (along with SecureBlackBox SSL support) and I find it to be great for my purposes.
Indy HTTP server calls the WinSock API, and is able to implement:
A full HTTP/1.1 server;
A full HTTPS server (using either OpenSSL libraries or other third parties, like SecureBlackBox).
AFAIK you can use Indy to publish web modules.
See http://www.2p.cz/files/2p.cz/downloads/howto/indy_soap_web_services_in_delphi.pdf
You can also use other servers, for instance directly the kernel-mode http.sys server, which is used by ISS and .Net WCF for instance, and known to be very stable and efficient (it bypasses the WinSock APIs). Of course, it will serve HTTPS conent, if needed. It is available in standard since Windows XP SP2, and therefore in Vista and Seven. Using this component will let Microsoft will do all the debugging work for you, and it will be updated with the host OS. I use it for instance in our Client-Server ORM, or directly to replace a deprecated DCOM connection, with very good speed and stability on customer side.
Regarding virtual servers - the HTTP 1.1 spec requires clients to send a Host request header so virtual servers know which domain is being used specifically to handle the case when multiple domains have the same IP. TIdHTTPRequestInfo has a Host property for that value. In fact, TIdHTTPServer internally validates to makes sure that an HTTP 1.1 request has the Host header before firing any of its OnCommand... events.

Using ASP.Net MVC & node.js together

I am writing a ASP.Net MVC app that connects to a SQL database and uses existing C# libraries I have.
I also have a TCP server Windows application that sends/receives TCP messages via XML. I have successfully setup node.js and socket.io to handle all this and have a html page that sends/receives messages to the server. Node.js is serving up the html page at the moment. The XML is converted to JSON when sending/receiving data.
I am planning on setting my MVC app to serve the page up but was just wondering what your thoughts are on this use of cross framework setup. Does it seem viable and a good solution for handling TCP messages and sending it to the browser? I have also read about iisnode for hosting node in IIS which I guess would be a good idea for my setup. What are your thoughts on this?
You basically have two websites. One is your ASP.NET MVC website. and the other is a web client for your TCP windows application.
Since they are disjoint it will work fine.
You may want to have that web client's html server through ASP.NET MVC and only run a websocket server on node.js though. You may need to do some proxying to get the same origin to work.
If you server your HTML page from a webserver running IP Y, port X and then try to talk to the node.js websocket server running on IP Y, port X + n it may violate the same origin restriction.
This means your basically loading a socket.io client from server A and trying to talk to server B. The web page doesn't know you own both of these servers.
The solution would be a proxy, you proxy all requests to server A and B but since they all go through the proxy it doesnt violate the same origin.
As for proxy, nginx is one. There is a node-proxy. And IIS might be able to proxy it for you (Although I doubt IIS makes a good proxy)

How can I access SQL server using ADO through a proxy?

I have a Delphi application that uses ADO to connect to a SQL server hosted on the Internet. The user running this application wants to access the SQL server through a proxy internally. How can this be done?
There is nothing special that needs to be done in the actual application, this is a networking problem, you would have to open some ports (1433 is the default) on the firewall for the communications to go through (going out)

Resources