Click here to Skip to main content
Licence 
First Posted 16 Oct 2007
Views 43,561
Downloads 263
Bookmarked 41 times

Tips to Make ASP.NET Talk to ASP, PHP, RAILS and JAVA (Part 1)

By Vijayaraghavan A Iyengar | 16 Oct 2007
Tips to integrate ASP.NET app with legacy ASP, PHP, RAILS, JAVA apps
1 vote, 11.1%
1

2

3
3 votes, 33.3%
4
5 votes, 55.6%
5
4.33/5 - 9 votes
μ 4.33, σa 2.37 [?]

Contents

Introduction

Screenshot - IntegrationTips0.jpg

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 Design

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.

Detailed Technical Design

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

Process Flow Diagram

Using the Code

ASPNETIntegrationServer.aspx.cs

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;
}

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>

Test PHP Add Example Using this Design

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:

  1. ASP.NET application takes input
  2. Calls TinyEAIPostRequest function passing URL and input
  3. Calls PHPListener passing values to add
  4. PHPListener receives the request
  5. Here goes our custom business logic - to make it simple, we just add the numbers
  6. PHPListener returns the result
  7. 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)
{
    //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 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=100Now click Test PHP Request button.
In ServerResponse TextBox you should get the added value.
The following screen should be displayed:

Your Inputs to Improve the Design

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.

Conclusion

A very simplistic approach to integrate ASP.NET with PHP, RAILS, ASP and Java platforms/language.

History

  • v1.0 11/08/07: Initial issue

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Vijayaraghavan A Iyengar



United States United States

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmembermanoj kumar choubey20:15 22 Jan '12  
GeneralMy vote of 4 Pinmembersomukarthi19:46 11 Jan '12  
GeneralError : The underlying connection was closed: An unexpected error occurred on a receive. Pinmembergs_dhaliwal15:42 21 Dec '09  
GeneralRe: Error : The underlying connection was closed: An unexpected error occurred on a receive. PinmemberVijayaraghavan Iyengar20:26 27 Dec '09  
GeneralRe: Error : The underlying connection was closed: An unexpected error occurred on a receive. PinmemberAnil From Bhilai, Chhattishgarh21:57 19 Nov '10  
QuestionThe advantage of an integration layer? Pinmemberdeostroll0:37 12 Aug '08  
GeneralTinyEAIPostRequest in VB.Net Pinmemberpsouza4micronet12:37 16 Oct '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120206.1 | Last Updated 16 Oct 2007
Article Copyright 2007 by Vijayaraghavan A Iyengar
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid