user774411
user774411

Reputation: 1809

How to send response to asp.net webform request via other server

I have two web servers with public IPs, for example Server1 with IP 111.111.111.111 and Server2 with IP 222.222.222.222. Please see the picture:

flow diagram

There is an asp.net webform at Server 1. My intention is:

  1. For every http request to that webform in Server1, the Server1 just pass the request's information to Server2 for logic processing and subsequently Server2 sends the response back to client (i.e. normal browser)

My questions are:

  1. What information that Server1 needs to pass to Server2, so that Server2 able to send response back to client? Please note that at Server2, there is a TcpListener instance. This TcpListener instance acting as receiver for that webform request information from Server1.
  2. What is the suitable object (i.e. the class in System.Net or related namespace such as System.Net.Sockets) at Server2 for sending response back to client? Suitable here means able to meet my intention.

Upvotes: 2

Views: 2235

Answers (6)

Predator
Predator

Reputation: 1275

Ok, this is a strange solution to that strange question :)

Basically I will assume the Client requests to an aspx web page as a QUESTION and the reply from Server as ANSWER. From the diagram, I will again assume that Server2 is the ANSWERER to that QUESTION.

In order for the Question and Answer session to work, and also due to internet behavior, I will implement it in a 2 steps process:

Step 1: Client ask question and Server1 returns the url of the answer. This url will be pointed on Server2. Server2 needs to pass this url via lan to Server1)

Step 2: Client makes request to retrieve the answer in Server2.

In summary, Client will directly request webform from Server1 and retrieve response from Server2. All operations are initiated by the Client.

Upvotes: 1

Nitin S
Nitin S

Reputation: 7600

The best solution for this problem is to setup a WCF web service on the other server.

ASP.NET WCF/Web Services supports interoperability with WCF applications running on the same Windows machine or WCF running on a different Windows machines or standard Web services built on platforms

Review following articles on msdn:

ASP.NET Web Services

ASP.NET Windows Communication Foundation in .NET

enter image description here

Upvotes: 2

John Leidegren
John Leidegren

Reputation: 61057

If you just wanna do request forwarding that's a simple matter of just forward the request to server2 by invoking a second request from server1 to server2. You then return that response as the response of server1 to the client. You cannot make server2 talk directly to the client because the client did not connect to server2.

I would use System.Net.HttpWebRequest and just set HTTP headers and content bodies based of the original request (effectively replaying the exact same message sent to server1 on server2) then return the response from server2 to the client.

If you did this you would be running an application which just forwards any requests to server2 and thus running a dummy application. This application can be very simple because in truth it is little more than a HTTP proxy.

Yet, I have to ask again, to what end? Are your building some kind of request filtering mechanism? because I believe there are better ways to solve that problem.

Upvotes: 1

adt
adt

Reputation: 4360

Well, client is connected Server 1 via http. that's ok but you want Server 2 to respond over TCP. this seems very unlikely to me, because clien doenst know anything about Server 2.

You might want to internally connect your server 2 from server 1 over tcp do your stuff and return your response from Server 1 to your client. ( Server 2 is acting like session state server for example)

If you are trying to load balancing its another story. Actually if you can tell us why you need such an architecture maybe you might get better answers.

Upvotes: 1

Peter Mourfield
Peter Mourfield

Reputation: 1885

We may need some more information about your scenario, but I don't think that Server2 can send the response back to the client.

The client still has an open socket listening for a response from Server1.

In order to accomplish something like this you may need to add some sort of proxy to the mix. Like this: client sends to proxy who sends to server 1, who sends to server 2, who sends response to proxy, who sends response to client.

Or have Server1 act as your proxy.

Upvotes: 1

Andrew Barber
Andrew Barber

Reputation: 40160

This sounds very suspicious to me, like something a phisher would want to do to hide the phishing attempt.

You really can't have a different server send a response directly back to the client than the one which directly receives the request. No client would accept such a response.

If this is a legitimate operation here, you need a proxy that accepts the request, and forwards the response back.

Upvotes: 1

Related Questions