Contents
While designing an application, the most difficult part is to integrate our application with existing applications. If we are lucky, the target application is also built on ASP.NET but most often these applications are created in different languages and make use of a different Framework. This article presents a design to solve the problem.
The high level design consists of an integration layer which makes the communication from ASP.NET to RAILS, PHP, ASP. This integration layer also shares the data from ASP.NET with RAILS, PHP, ASP and Java. This design can also be extended to other applications created in other languages with changes.
The detailed design of the Integration Layer consists of two main sections:
ASPNETIntegrationServer
- It is implemented using ASP.NET page which takes the data from an ASP.NET application and passes it to the target application by calling the respective listener as shown in the diagram
Listener
ASPListener
(This block resides in ASP WebServer Box)
- Step 1: Reads the data passed by the ASP.NET page
- Step 2: Processes the request and custom business logic in ASP
- Step 3: Returns the result back to ASP.NET page
PHPListener
(This block resides in PHP WebServer Box)
- Step 1: Reads the data passed by the ASP.NET page
- Step 2: Processes the request and custom business logic in PHP
- Step 3: Returns the result back to ASP.NET page
RailsListener
(This block resides in RAILS WebServer Box)
- Step 1: Reads the data passed by the ASP.NET page
- Step 2: Processes the request and custom business logic in Ruby
- Step 3: Returns the result back to ASP.NET page
JavaListener
(This block resides in Java Tomcat WebServer Box)
[Please note Java Listener is not implemented in tiny EAI code]
- Step 1: Reads the data passed by the ASP.NET page
- Step 2: Processes the request and custom business logic in Java
- Step 3: Returns the result back to ASP.NET page
ASPNETIntegrationServer.aspx.cs
Logic to call listener by passing value as HTTPGet
and then redirect to the page:
string strRequest;
strRequest = "Value to Pass";
Response.Redirect
(http:
Response.Redirect
(http:
Response.Redirect
("http://railsserver/RailsListener/integrate?aspPassedValue=
" + strRequest);
Logic to call listener and read the value in code:
public string TinyEAIPostRequest(string strURL,string strRequest)
{
HttpWebResponse objHttpWebResponse = null;
UTF8Encoding encoding;
string strResponse = "";
HttpWebRequest objHttpWebRequest;
objHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
objHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
objHttpWebRequest.PreAuthenticate = true;
objHttpWebRequest.Method = "POST";
if (strRequest != null && strRequest != string.Empty)
{
encoding = new UTF8Encoding();
Stream objStream = objHttpWebRequest.GetRequestStream();
Byte[] Buffer = encoding.GetBytes(strRequest);
objStream.Write(Buffer, 0, Buffer.Length);
objStream.Close();
}
objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();
encoding = new UTF8Encoding();
StreamReader objStreamReader =
new StreamReader(objHttpWebResponse.GetResponseStream(),encoding);
strResponse = objStreamReader.ReadToEnd();
objHttpWebResponse.Close();
objHttpWebRequest= null;
return strResponse;
}
PHPListener.php
<?php
#Receive ASP.NET passed values
#Data from ASP.NET can be passed as POST or GET Requests
echo 'php received :- ' . $_GET['aspNetPassedValueByGet' ]
echo 'php received :- ' . $_POST['aspNetPassedValueByPost' ]
#Your php logic goes here
?>
ASPListener.asp
<%
'Receive ASP.NET passed values
'Data from ASP.NET can be passed as POST or GET Requests
Response.Write "asp received :- " +
Request.QueryString("aspNetPassedValueByGet")
Response.Write "asp received :- " + Request.Form('aspNetPassedValueByPOST')
'Your asp logic goes here
%>
RailsListenerController.rb
class RailsListenerController < ApplicationController
def integrate
@aspValue = @params["aspPassedValue"]
end
end
integrate.rhtml
<html>
<head></head>
<body>
ASP.NET Passed value <%=@aspValue
%>
</body>
</html>
This is a simple addition example using a PHP Listener where business logic written in PHP adds the values passed by ASP.NET and then returns the result back to the ASP.NET application. Please find below the internal steps which are performed to do this action:
- ASP.NET application takes input
- Calls
TinyEAIPostRequest
function passing URL and input
- Calls
PHPListener
passing values to add
PHPListener
receives the request
- Here goes our custom business logic - to make it simple, we just add the numbers
PHPListener
returns the result
- ASP.NET shows the results back to the user
PHPListener.php: Puts this File in PHP Server
<?php
$value1 = $_POST['value1'];
$value2 = $_POST['value2'];
#Here goes our custom business logic
#Just add the two numbers and return
echo $value1 + $value2 ;
?>
TinyEAI: Host the TinyEAI on ASP.NET Server
Change the URL in ASPNETIntegrationServer.aspx.cs file to point to the above PHPListener
as shown below:
protected void btnTestCallandReturn_Click(object sender, EventArgs e)
{
txtResult.Text = TinyEAIPostRequest
("http://localhost:8081/phpListener.php", txtRequest.Text);
}
Testing our Example
Open the following link in the browser: http://yourASPNETServer/tinyEAI/ASPNETIntegrationServer.aspx
The following screen should be displayed:
Testing our Example
In the ServerRequest
TextBox, enter Value1=2&Value2=100
Now click Test PHP Request button.
In ServerResponse
TextBox you should get the added value.
The following screen should be displayed:
Please give your inputs to improve this design and tips to make it more scalable and easy to implement and do share your thoughts on your integration designs.
I would just like to ask, if you liked the article please vote for it, and leave some comments, as it lets me know if the article was at the right level or not, and whether it contained what people need to know.
A very simplistic approach to integrate ASP.NET with PHP, RAILS, ASP and Java platforms/language.
- v1.0 11/08/07: Initial issue