|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Contents
Introduction
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. High Level DesignThe 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. Detailed Technical DesignThe detailed design of the Integration Layer consists of two main sections:
Process Flow Diagram
Using the CodeASPNETIntegrationServer.aspx.csLogic to call listener by passing value as string strRequest;
strRequest = "Value to Pass";
//code to call asplistener
Response.Redirect
(http://aspserver/PHPListener.php?aspNetPassedValueByGet= + strRequest);
//code to call phplistener
Response.Redirect
(http://phpserver/ASPListener.asp?aspNetPassedValueByGet= + strRequest);
//code to call railslistener
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";
//Prepare the request stream
if (strRequest != null && strRequest != string.Empty)
{
encoding = new UTF8Encoding();
Stream objStream = objHttpWebRequest.GetRequestStream();
Byte[] Buffer = encoding.GetBytes(strRequest);
// Post the request
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.rbclass RailsListenerController < ApplicationController
def integrate
@aspValue = @params["aspPassedValue"]
end
end
integrate.rhtml<html>
<head></head>
<body>
ASP.NET Passed value <%=@aspValue
%>
</body>
</html>
Test PHP Add Example Using this DesignThis 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:
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 ServerChange the URL in ASPNETIntegrationServer.aspx.cs file to point to the above protected void btnTestCallandReturn_Click(object sender, EventArgs e)
{
//As we get only one return value so we assign
//all the response back to txtResults
//For complex types we can make the Listener return XML
//which can be loaded to XMLDOM and use it.
txtResult.Text = TinyEAIPostRequest
("http://localhost:8081/phpListener.php", txtRequest.Text);
}
Testing our ExampleOpen the following link in the browser: http://yourASPNETServer/tinyEAI/ASPNETIntegrationServer.aspx Testing our ExampleIn the Your Inputs to Improve the DesignPlease 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. ConclusionA very simplistic approach to integrate ASP.NET with PHP, RAILS, ASP and Java platforms/language. History
|
|||||||||||||||||||||||||||||||||||||||||||||||