![]() |
Languages »
C# »
Applications
Intermediate
Tips to Make ASP.NET Talk to ASP, PHP, RAILS and JAVA (Part 1)By Vijayaraghavan A IyengarTips to integrate ASP.NET app with legacy ASP, PHP, RAILS, JAVA apps |
C#, Windows, Java, .NET 2.0, ASP.NET, Visual Studio, PHP, WebForms, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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 Listener ASPListener (This block resides in ASP WebServer Box)PHPListener (This block resides in PHP WebServer Box) RailsListener (This block resides in RAILS WebServer Box) JavaListener (This block resides in Java Tomcat WebServer Box)
Logic to call listener by passing value as HTTPGet and then redirect to the page:
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;
}
<?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
?>
<%
'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
%>
class RailsListenerController < ApplicationController
def integrate
@aspValue = @params["aspPassedValue"]
end
end
<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:
TinyEAIPostRequest function passing URL and inputPHPListener passing values to addPHPListener receives the requestPHPListener returns the result <?php
$value1 = $_POST['value1'];
$value2 = $_POST['value2'];
#Here goes our custom business logic
#Just add the two numbers and return
echo $value1 + $value2 ;
?>
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)
{
//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);
}
Open the following link in the browser: http://yourASPNETServer/tinyEAI/ASPNETIntegrationServer.aspx
The following screen should be displayed:
In the ServerRequest TextBox, enter Value1=2&Value2=100Now 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.
| You must Sign In to use this message board. | |||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 16 Oct 2007 Editor: Deeksha Shenoy |
Copyright 2007 by Vijayaraghavan A Iyengar Everything else Copyright © CodeProject, 1999-2009 Web11 | Advertise on the Code Project |