Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts

Monday, December 6, 2010

Calling Web Service using ASP.NET

Shows how to call a Web service inside ASP.NET Web project using a test published Web service: Extentrix Web Services 2.0 Application Edition

Introduction

Web services signal a new age of trivial distributed application development. While Web services are not intended nor do they have the power to solve every distributed application problem, they are an easy way to create and consume services over the Internet. One of the design goals for Web Services is to allow companies and developers to share services with other companies in a simple way over the Internet.
Web services take Web applications to the next level.
Using Web services, your application can publish its function or message to the rest of the world.
Web services use XML to code and decode your data and SOAP to transport it using open protocols.
With Web services, your accounting departments Win 2K servers' billing system can connect with your IT suppliers UNIX server.
Using Web services, you can exchange data between different applications and different platforms.
With Microsoft .NET platform, it is a simple task to create and consume Web Services. In this article, I am going to show how to call a published Web service inside a Web project.
I use a test published Web service; Extentrix Web Services 2.0 Application Edition that Extentrix published for the developer community to help them in testing and developing.
So I'll simply explain the functions of this Web services APIs. In general Extentrix Web Services for Citrix Presentation Server helps you get information about a published application for a specific client with the specified details, server types, and client types. It also returns the ICAfile description to be used to launch an application with a given parameter and checks the user's credentials and returns true if they are valid.
For more information, visit this website.
You can find more samples, use this web service, and test it here.

Background

Knowledge in ASP.NET is preferred.

Using the Code

Simple Steps to Consume a Web Service

  1. Create a Web Site project
  2. Add a Web Reference
  3. Call the Web services APIs inside the code

First Step: Create a Web Site Project

  1. To create a new Web Site project, choose New from File menu, then choose Web Site as shown below:

  2. Choose ASP.NET Web Site. Name the project and click OK:

Second Step: Add a Web Reference

After creating the Web Site project, it�s time to add a Web reference for our Web service.
  1. In the solution explorer, right click the project node, choose Add Web Reference:

  2. A new window with Add Web Reference title will be opened:

    In the URL field, insert the URL for the Web service. In this tutorial, as I mentioned before, I'll use the test published Web services from Extentrix: �Extentrix Web Services 2.0 � Application Edition�.
    After clicking the Go button, you will see the Web services APIs.
  3. Set a name for your Web service reference in the Web reference name field and click Add Reference:

Third Step: Call the Web Services APIs Inside the Code

After successfully adding to the Web service, now we are ready to call the Web services APIs inside our project.
  1. First we need to add the added Web reference to our class.
    ExtentrixWS is the name of the added Web service from the previous step.

    Collapse
    using ExtentrixWS;  
  2. Create a proxy object for our added Web service reference, where ExtentrixWebServicesForCPS is the name of the Web Services.

    Collapse
    //define a Web service proxy object.
    private ExtentrixWS.ExtentrixWebServicesForCPS proxy;
  3. As I explained before, we need credentials to pass to the Citrix Presentation Server. We will pass these credentials through the Web services APIs:

    Collapse
    //define a Citrix Presentation Server Credentials object
    private Credentials credentials;
    Initialize the proxy and the credentials objects:
    Collapse
    //initialize objects
    proxy = new ExtentrixWebServicesForCPS();
    credentials = new Credentials();
  4. Set the values for Citrix credentials. I set the credentials values for the test of Extentrix Web Service:

    Collapse
    //set credentials
    //these values are according to Citrix testdrive presentation server
    //for which Extentrix published a web service for developers to use it
    //as a test web service.
          credentials.Password = "demo";
          credentials.UserName = "citrixdesktop";
          credentials.Domain = "testdrive";
    
    //because it is a sample, we will use no encryption method.
    //so the password will be sent as a clear text.
          credentials.PasswordEncryptionMethod = 0;
    
    //set the domain type to windows domain
          credentials.DomainType = 0;
    Now we can call any Web services available. It is as simple as calling any ordinary function.
  5. Call the GetApplicationsByCredentialsEx Web service. This web service takes the following parameters:
    • Credentials: Citrix Credential to access Citrix Presentation Server Farm
    • Client Name: Pass your machine name
    • Client IP: Pass your machine IP
    • Desired Details : Details you asked for
    • Server Types: Pass �all�
    • Client Types: Pass �all�
I am not going to explain Extentrix Web services APIs, if you are interested, you can go here and look for it.
This API returns an array of ApplicationItemEx. This class will be built for you once you add the Web reference.
This class contains the published application properties. I used this Web service to get all the published applications, and then I created an ImageButton for each application.
Collapse
// 1) Get all the published applications list by calling GetApplicationsByCredentialsEx 
//    web service.
// 2) create an ImageButton for each application
// 3) Create Image for the application
// 4) Add it to the AppList panel.
// 5) Set the event handler for each ImageButton, so when clicking it the associated 
//    application will run calling the web service
ApplicationItemEx[] items = proxy.GetApplicationsByCredentialsEx
    (credentials, Request.UserHostName,
Request.UserHostAddress, new  string[] { "icon","icon-info"}, new string[]{ "all" },
new string[] { "all"});

//loop for each published application
for (int i = 0; i < items.Length; i++) {
//create the ImageButton
System.Web.UI.WebControls.ImageButton app = new System.Web.UI.WebControls.ImageButton();

//set the Image URL to the created image
app.ImageUrl = createIcon(items[i].InternalName,items[i].Icon);

//set the ToolTip to the name of the published application
app.ToolTip = items[i].InternalName;

//add the ImageButton to the AppList panel
AppList.Controls.Add(app);

//set the event handler for the ImageButton.
app.Click += new
System.Web.UI.ImageClickEventHandler(this.OnApplicationClicked);
}
Finally, another example in calling a Web service is to launch the published application.
In this example, in the event handler of the applications ImageButtons I launch the clicked application.
I get the ICA file content by calling LaunchApplication Web service. Then I write the ICA file content to the response to launch the application.
Collapse
private
void OnApplicationClicked (object sender, System.EventArgs e)
{
    ServicePointManager.Expect100Continue = false;

    // Get the event source object.
    System.Web.UI.WebControls.ImageButton app = 
        (System.Web.UI.WebControls.ImageButton)sender;

    //Get the file ICAfile content by calling LaunchApplication web service.
    string = proxy.LaunchApplication(app.ToolTip, credentials, Request.UserHostName, 
            Request.UserHostAddress);

    //Set the response content type to "application/x-ica" to run the file.
    Response.ContentType = "application/x-ica";

    //Run the application by writing the file content to the response.
    Response.BinaryWrite(Response.ContentEncoding.GetBytes(ica));        
    Response.End();
}

Sunday, December 5, 2010

Web Services with ASP.NET

Web Services with ASP.NET


  Rob Howard
Microsoft Corporation
February 22, 2001
Web Services are the underpinning of Microsoft's .NET strategy. The concepts and the innovations behind this initiative have struck a chord with developer's building the next generation of Internet applications.
In this month's column, we're going to take a look at the features within ASP.NET to enable Web Services. Before we dig into the technical details let's start with an overview of Web Services.

Web Services Overview

A Web Service is programmable application logic accessible via standard Web protocols. One of these Web protocols is the Simple Object Access Protocol (SOAP). SOAP is a W3C submitted note (as of May 2000) that uses standards based technologies (XML for data description and HTTP for transport) to encode and transmit application data.
Consumers of a Web Service do not need to know anything about the platform, object model, or programming language used to implement the service; they only need to understand how to send and receive SOAP messages (HTTP and XML).

Soap Message

A SOAP message consists of several elements, most notably an envelope. The envelope encapsulates the data transmitted within the SOAP message. Below is a simple SOAP message complete with HTTP headers:

POST /demo/MSDN/PerfCounter.asmx HTTP/1.1
Connection: Keep-Alive
Content-Length: 150
Content-Type: text/xml
Host: localhost
User-Agent: MS Web Services Client Protocol 1.0.2204.19
SOAPAction: "http://tempuri.org/PerfCounters"



               xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
               xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/1999/XMLSchema">
  
    
  
In the example above, we see the HTTP headers for the request, including the HTTP SOAPAction header, which is optionally used by the server for routing the SOAP message. Following the HTTP headers we find the body of the HTTP message. The body of the HTTP message is the SOAP request for a PerfCounters Web Service, which we are going to build.
Unfortunately we don't have nearly enough room in this column to discuss SOAP in depth. To learn more about SOAP, please see the SOAP Developer Resources page. Here you can find the public specification for SOAP 1.1 as well as articles and other relevant resources.

ASP.NET Web Services

Web Services are simple and easy to understand. It is possible, in fact, to author a simple application that surfaces data as XML conforming to the SOAP specification. It would also be relatively straightforward to build an application capable of receiving SOAP messages over HTTP and deriving meaningful value out of it. For those of you familiar with PERL, this could simply be a matter of using RegEx to parse the value out of the XML result; it's just another string.
However, just as we use frameworks such as ASP and ASP.NET to build Web applications, we would much rather use a framework for building Web Services. The reasoning is quite logical. We don't need to reinvent the plumbing—that is, at a high level, the capability to serialize our data as XML, transport the data using HTTP, and de-serialize the XML back to meaningful data. Instead, we want a framework that makes building Web Services easy, allowing us to focus on the application logic not the plumbing. ASP.NET provides this framework for us.
From a developer's point of view, if you have ever written application logic, you have the required skills to author ASP.NET Web Services. More importantly, if you're at all familiar with ASP or ASP.NET application services, (application state memory, and so on) you can also leverage these skills when you build ASP.NET Web Services.

Exposing

For the purpose of example, we're going to write a Web Service that exposes Web application performance counters. Performance counters provide us with details about the behavior of our application, such as the number of active sessions or the number of requests served. We don't always have local server access to our Web server, and if we have a farm of servers we might want to expose the performance counters from all these servers and aggregate them in a central location.

Starting with a Simple Example

Rather than jumping straight into the Performance Counters example, let's start with some very simple application logic so we can see what we need to do to expose our logic as a Web Service. We'll use an Add() method that accepts two Integers and returns their sum. Below is this simple Visual Basic logic:

Public Class MyMath
  Public Function Add(a As Integer, b As Integer) As Integer
    Return a + b
  End Function
End Class
We could use this class and its method as follows:

Dim mymath As new MyMath
Dim result As Integer
result = mymath.Add(10, 20)
To expose the above class, MyMath, as an ASP.NET Web Service we need to move the application logic into a *.asmx file. Just as we use the extension *.aspx for ASP.NET Pages, we use *.asmx to tell ASP.NET that the file is an ASP.NET Web Service.
After we created the *.asmx source file and add our application logic, we need to make a few more small changes:

<%@ WebService Language="VB" Class="MyMath" %>
Public Class MyMath
  Public Function Add(a As Integer, b As Integer) As Integer
    Return a + b
  End Function
End Class

Changes to our source

The changes we've made to the *.asmx file include adding a WebService directive that names both the Language as well as the Class we're exposing as a Web Service. The WebService directive is required, as we must tell ASP.NET the class that contains the application logic. Next, we've added a attribute to our Add() function declaration. An attribute is a declarative code element that lets us change the behavior of our application logic without necessarily writing more code. In the case of the attribute, this tells ASP.NET that the method with this attribute is to be treated as 'Web callable'. Web callable in the sense that ASP.NET does the necessary work for this method to support SOAP.
Now that we've seen what needs to be done to enable application logic as Web callable, let's look at a more relevant sample.

Performance Counter Web Service

Below is application logic that gives us access to the Windows® performance counters, with the changes for ASP.NET Web Services. The file we've created is PerfCounter.asmx:

<%@ WebService language="VB" class="PerfCounters" %>
Imports System.Xml.Serialization
Imports System.Web.Services
Imports System.Diagnostics
 
Public Class PerfCounters
  Inherits WebService
 
  ' Returns a Counter class
  Public Function GetCounters() As Counters
    Dim c As new Counters
 
    ' Application Name
    c.ApplicationName              = IISAppName
 
    ' System specific
    c.WorkerProcessRestarts = Poll(0, "Worker Process Restarts")
    c.WorkerProcessRunning  = Poll(0, "Worker Process Running")
    c.ApplicationsRunning   = Poll(0, "Applications Running")
    c.RequestsQueued        = Poll(0, "Requests Queued")
 
    ' Application Specific
    c.RequestsTotal         = Poll(1, "Requests Total")     
    c.RequestsFailed        = Poll(1, "Requests Failed")   
    c.RequestsSucceeded     = Poll(1, "Requests Succeeded")
    c.ActiveSessions        = Poll(1, "Sessions Active")
 
    Return c
  End Function
 
  Private Function Poll(counterType As Integer, counter As String) As Integer
     Dim PerfCounter As PerformanceCounter
 
     If (counterType = 0)
       PerfCounter = new PerformanceCounter("ASP Plus System", counter, "")
     Else
       PerfCounter = new PerformanceCounter("ASP Plus Applications", counter, IISAppName)
     End If
 
     Return PerfCounter.NextValue().ToInt32()
  End Function
 
  Private Function IISAppName() As String
    Dim AppName As String
    
    AppName = Context.Request.ServerVariables("APPL_MD_PATH")
    AppName = AppName.Replace("/"C, "_"C)
 
    Return AppName
  End Function
End Class
 
Public Class Counters
  Public ApplicationName As String
  Public WorkerProcessRestarts As Integer
  Public WorkerProcessRunning As Integer
  Public ApplicationsRunning As Integer
  Public RequestsQueued As Integer
  Public RequestsTotal As Integer
  Public RequestsFailed As Integer
  Public RequestsSucceeded As Integer
  Public ActiveSessions As Integer
End Class
Again we see that we've declared a WebService directive at the top of the file noting both the language and the class. The class that contains the Web callable method is PerfCounters. Within PerfCounters we find a single method, GetCounters(), with the attribute. GetCounters() returns an instance of another class, Counters.
When we call GetCounters(), the method creates a new instance of the Counter class and begins to set its public members; note, these public members should be implemented as properties, but I chose to save the space for the purpose of the article.
When the Counter class' members are set, we're setting them with the returned result of a call to a private method Poll(). Poll() is responsible for doing the actual work of polling the systems performance counters and returning a result.
Finally, the last method, IISAppName(), returns the value of the server variable APPL_MD_PATH and replaces '/' characters with '_' characters; this value is used as the application name within the performance counters.
Now that we've built the service, let's take a look at how we test it.

Testing Web Services

Now that we've authored this ASP.NET Web Service, how do we test it? The consumer of a Web Service is another application, but ASP.NET provides a simple browser interface to our Web Service that we can use for testing or documentation purposes.
Since our service is exposed as a resource available from our Web server, we can simply open a browser and make a request for that resource. Doing so provides us with a nice HTML-based Web Service Help page that lets people learn about what our service provides:
Figure 1. HTML-based Web Service Help page
ASP.NET generates the above page for us, and we can use it to test our service (note the HTML Invoke button within the GetCounters Web Method section) and access the XML contract language used to describe what our service offers; we'll be coming back to the XML contract language momentarily.
If we press the Invoke button, a new browser window is opened, and a request is made to our service using HTTP-Get; one of the three supported protocols used by ASP.NET Web Services:
Figure 2. Example of the new browser window that is created when pressing the Invoke button.
The XML returned is a valid XML document that describes all of the settings we identified in our Counters class. However, it is not SOAP. SOAP is the default protocol that is used when we do application-to-application communication.
Although we didn't discuss it in this article, we can customize our help page quite extensively. This is done by making some changes to the ASP.NET configuration system, or modifying the DefaultSDLHelpGenerator.aspx. I would recommend not modifying the DefaultSDLHelpGenerator.aspx, as this is the template used for all our Web Services. Instead, make a copy of it and reference the copied version in the application's configuration that makes use of it.
Now that we've discussed authoring and testing our Web Service, let's make use of it.

Consuming

We have several options for consuming Web Services. Since this article is about ASP.NET, we'll focus on .NET technologies that can consume Web Services. However, I should point out that any platform or framework that understands SOAP should be able to communicate with our Web Service. Building the Web Service with ASP.NET does not mean that the service is only available to other Microsoft applications.
Consumers of a Web Service need to know what the service offers—for example, what its Web callable method look like. Therefore, all Web Services optionally share another common XML document: a contract (note, Web Services built with ASP.NET always have a contract provided automatically).

Contract

In the examples above when we discussed testing a Web Service, we didn't discuss the link found within Web Service Help Page: SDL Contract. If we were to follow that link, instead of pressing the Invoke button for the GetCounters() Web Method, we would be presented with the following XML document:
Figure 3. XML document presented when following the link found within the Web Service Help Page
This XML document is a contract that describes our Web Service. It details the protocols supported as well as the semantics for calling and returning values. It additionally defines an XML schema for our Counters class.
Tools can use this XML schema to build proxy classes for our Web Service. A proxy class is a class that looks and feels like a local object, but it is in fact doing the work to serialize, send, receive, and de-serialize our method request to a SOAP endpoint.
Note   Beta 1 of .NET surfaces an "SDL—Service Description Language" contract, Beta 2 will switch to use the more recent "WSDL—Web Service Description Language" contract. Semantically they are very different. WSDL is the collaborative work of Microsoft, IBM, and several other companies to better standardize the XML contract language.
We have various options for consuming Web Services, however, I'd like to call out three in particular:
  • Visual Studio .NET: —Visual Studio .NET does the work of creating the proxy from the SDL or WSDL and adds the appropriate code to our project. This is done by simply selecting Project | Web References, and then pointing at a valid contract. Note that for beta 1 the contract must be SDL.
  • Command Line Tools: —The .NET SDK ships with a tool called WebServiceUtil.exe that accepts an SDL contract and can generate the proxy source code for Visual Basic .NET, C#, or JScript.NET.
  • IE 5.5. Behavior: —A browser specific behavior that allows for rich client interaction with SOAP end-points. For those of you familiar with Remote Scripting, you're going to love this! To learn more about the IE 5.5 behavior, please see WebService Behavior.
Unfortunately, we don't have the space to discuss these three options in detail. However, I thought it would be worthwhile to briefly cover building a proxy with the command line tool, as this is applicable to those who have installed .NET; not just those that have Visual Studio .NET.

Command line tool

.NET, whether you install it as part of Visual Studio .NET or the .NET SDK, includes a command line proxy generation tool called WebServiceUtil.exe. The path to this command line tool, as well as several other command line tools, is added to our path when we installed .NET.
WebServiceUtil.exe allows us to name a SDL, or contract, as one of the command line arguments and the tool can then generate the source code for a proxy to our Web Service.
If, for example, we were to save the SDL from our PerfCounters.asmx example, we could use WebServiceUtil.exe to generate a Visual Basic .NET proxy to this Web Service:

WebServiceUtil.exe /command:proxy PerfCounter.sdl /language:VB
This generates a source file PerfCounters.vb that we now need to compile.
Using the VB.NET command line compiler, vbc.exe, we can compile our VB source file:

vbc /t:library /r:system.web.dll /r:system.web.services.dll /r:system.xml.serialization.dll perfcounters.vb
What we've done with the command line compiler is specify that we want to create a library (dll) rather than an executable (exe), and in addition to naming the source file to compile, we've specified some .NET assemblies (libraries containing classes our source file requires) as arguments to the compiler.
The result is PerfCounters.dll, a complete proxy to our PerfCounters.asmx ASP.NET Web Service that we can now use in .NET applications to communicate via SOAP to our Web Service.
Let's use this proxy to build a simple ASP.NET page that consumes and uses our Web Service.

Using the Web Service

First we need to deploy the compiled proxy, known as an assembly, to a Web application's \bin directory. Although we haven't discussed deploying compiled code in this column yet (yet another topic for a future column), suffice to say that to 'register' an assembly on the system simply requires copying the *.dll to a Web application's \bin directory. This is a feature of .NET, but the use of the \bin directory is specific for ASP.NET.
To make things simple, we'll create a bin directory off of the server's root directory, c:\inetpub\wwwroot\bin for example. A \bin directory must exist in an application root, either the root of the Web or a folder marked as an application in IIS.
Next, we copy our assembly, PerfCounters.dll, to our \bin directory. We can now author our ASP.NET page, which we'll deploy to c:\inetpub\wwwroot. We'll call it PerfCountersConsume.aspx:


Web Application: 

Process Restarts: 

Processes Running: 

Applications Running: 

Requests Queued: 

Requests Total: 

Requests Failed: 

Requests Succeeded: 

Active Sessions: 

The code above creates an instance of our proxy class PerfCounters (available to us since it's a registered assembly in our \bin directory) calls its GetCounters() method and returns an instance of a Counters class. We then use the instance of the Counters class, counters, to request its member variables and populate ASP.NET server controls. The result is below:


Figure 4. ASP.NET server controls

Summary

This column has taken a very high level overview of ASP.NET Web Services. There's quite a bit of detail that we either glossed over or didn't cover at all, for example security, use of session state, extensions, and so on. In next month's column we're going to look at a more advanced feature of ASP.NET Web Services, extensions, that we can use for building attributes that allow us to trace the request/response of our ASP.NET Web Service.
Rob Howard is a program manager for ASP.NET on the .NET Framework team. He spends whatever spare time he has either with his family or fly fishing in Eastern Washington.

Sunday, November 14, 2010

Migrating from PHP to ASP.NET- part4

Output
The typical way of outputting data in PHP is through the echo() language construct.
closest analogue to this in ASP.NET is the Response.Write() method, or the
'

Code Sample 3. Basic output in PHP




$hello = "hi how are you\n";

echo $hello;

?>

Code Sample 3. Basic output in Visual Basic .NET

However, these methods for sending output to the browser exist primarily for backwards compatibility with classic ASP. ASP.NET's new control-based, event-oriented model allows for data to be output to the browser by simply setting properties on server controls. This technique allows for clean separation of layout and code and can make maintenance easier, requiring significantly less code in complex situations than PHP.



The current date is:

This example declares a server-side Label control called TheDate, and during the page's Load event, sets the Text property of the label to the current date and time. The HTML output of this code is identical to the other two versions, except that the Label control renders itself as a span tag containing whatever was set as the label's text.

Conditional Processing

IF/ELSE

PHP has several conditional processing expressions such as for, while, switch, and foreach but the most common is the if/else expression. Visual Basic .NET has very similar constructs with similar syntax. Code Sample 4 provides a comparison of equivalent conditional logic in PHP and Visual Basic .NET.

Code Sample 4. Basic conditional logic in PHP

if ($a > $b) {

print "a is bigger than b";

} elseif ($a == $b) {

print "a is equal to b";

} else {

print "a is smaller than b";

}



Code Sample 4. Basic conditional logic in Visual Basic .NET

If a > b

Response.Write ("a is bigger than b")

ElseIf a = b Then

Response.Write ("a is equal to b")

Else

Response.Write ("a is smaller than b")

End If



Switch

Switch statements are common language constructs for most programming languages when you wish to test a single expression for multiple values. They are commonly used to replace if statements that contain multiple elseif/else blocks.

Code Sample 5 shows a comparison between PHP's switch statement and Visual Basic's Select Case statement.

Code Sample 5. A switch statement in PHP

switch ($i) {

case 0:

print "i equals 0";

break;

case 1:

print "i equals 1";

break;

case 2:

print "i equals 2";

break;

default:

print "i is not equal to 0, 1 or 2";

}



Code Sample 5. A Select Case statement in Visual Basic .NET

Select Case Number i

Case 0

description = "0"

Wesponse.Write ("i equals 0")

Case 1

description = "1"

Response.Write ("i equals 1")

Case 2

description = "2"

Response.Write ("i equals 2")

Case Else

description = " i is not equal to 0, 1 or 2"

Response.Write ("i is not equal to 0, 1 or 2 ")

End Select

Thursday, November 11, 2010

a fast growing software and web development (C# ASP.NET 3.5) company is seeking to hire highly talented, qualified and motivated junior/Sernior software developers. Cadidates from both genders are welcomed. Computer science or science - Computer major graduates are preferred. Please send your CV to info@jadeedsolutions.com or Call 0114221084 for more inquiries

a fast growing software and web development (C# ASP.NET 3.5) company is seeking to hire highly talented, qualified and motivated junior/Sernior software developers. Cadidates from both genders are welcomed. Computer science or science - Computer major graduates are preferred. Please send your CV to mailto:info%40jadeedsolutions.com or Call 0114221084 for more inquiries

Junior ASP.NET Web Developer

Junior .Net Developer (1+ years of experience)


Candidates must have



•Very good knowledege in OOP and ERD



•Very good experience in ASP.NET

•Very good experience in HTML

•Very good experience in CSS

•Very good experience in JavaScript



•Very Good knowledege in JQuery, AJAX

•Good experience in SQL Server



Additional Skills & Competencies:

• Building and facilitating effective project development teams or integrated project teams.

• A self-starter who requires minimal supervision.

• Excellent interpersonal and organizational skills, ability to handle diverse situations, multiple projects and rapidly changing priorities.

• Ability to communicate with clients at all levels.

• Ability to come up with the best solution for given requirements.

• Ability to provide reasonably accurate estimates for projects, based on client-provided technical and functional requirements.

Resumes to be sent to NewJob.Developers@yahoo.com



Migrating from PHP to ASP.NET- part3

Comparing Syntax and Common Tasks

The following sections provide comparisons between PHP and .NET syntax as well as how to accomplish some of the more common programming tasks.

Comments

PHP allows you to insert comments in your code using C, C++ and Unix shell-style syntax, and anything within those comment indicators will not be executed.

In general, to comment out Visual Basic .NET code in ASP.NET you just need to use to close the block.

Code Sample 1 shows comments in each environment.

Code Sample 1. Server-side comments in PHP

/*

This is a block of text

That has been commented out

*/



Code Sample 1. Server-side comments in ASP.NET

Variables

While PHP and Visual Basic .NET have similar language constructs, they are very different syntax for them. Since Visual Basic .NET is built upon an OOP model, variable declaration is much more rigorous than in PHP where a variable is declared simply by adding a dollar sign ($) before the variable name.

In Visual Basic .NET you declare a variable by specifying its name and characteristics. The declaration statement for variables is the Dim keyword. Its location and contents determine the variable's characteristics. Variables have levels such as local and module, data types, lifetimes and finally accessibility.

While this approach may seem more complex at first than variable assignment in PHP it actually makes a developer's life easier. ASP.NET focuses on helping developers build robust applications—and specifying data types makes tasks such as variable clean up, debugging, exception and error handling, and code maintenance much easier.

Code Sample 2 shows examples of declaring variables in each environment.

Code Sample 2. Variable declaration in PHP

$head_count

$foo

$X

$obj



Code Sample 2. Variable declaration in Visual Basic .NET

Dim head_count As Integer

Dim foo As String

Dim X As Date

Dim Obj As object



Declaring Data Types


The AS clause in the declaration statement allows you to define the data type or object type of the variable you are declaring. You can specify any of the following types for a variable:

• An elementary data type, such as Boolean, Long, or Decimal

• A composite data type, such as an array or structure

• An object type, or class, from Visual Basic or another application, such as Label or TextBox

You can declare several variables of the same type in one statement without having to repeat the data type. In the following statements, the variables numStudents, numGTA and numProfessors are declared as type Integer:

Dim numStudents, numGTA , numProfessors As Integer

' All three are Integer variables.



For more information on data types, see Data Types. For more information on object-oriented programming, see Object-Oriented Programming in Visual Basic.

Declaring Lifetime

The lifetime of a variable is the period of time during which it is available for use. A local variable declared with a Dim statement exists only as long as its procedure is executing. When the procedure terminates, all its local variables disappear and their values are lost.

The concept of lifetime is extremely useful in that it allows developers to build applications with out having to concern them selves with many issues that occur in large-scale applications such as efficient memory management. By selecting the correct lifetime for a variable you can allow .NET to perform clean up operations on variables that are not being used.

For more information on lifetime, see Lifetime.

Declaring Scope

A local variable is one that is declared within a procedure (a procedure is analogous to a function). A non-local variable is one that is declared outside a procedure, but within a class or structure.

In a class or structure, the category of a non-local variable depends on whether or not it is shared. If it is declared with the Shared keyword, it is a shared variable, and it exists in a single copy shared among all instances of the class or structure. Otherwise it is an instance variable, and a separate copy of it is created for each instance of the class or structure. A given copy of an instance variable is available only to the instance for which it was created.

The scope of a variable is the set of all code that can refer to it without qualifying its name. A variable's scope is determined by where the variable is declared. Code located in a given region can use the variables defined in that region without having to qualify their names. When declaring scope, the following rules apply:

• The scope of a shared or instance variable is the structure or class in which it is declared.

• The scope of a local variable is the procedure in which it is declared.

However, if you declare a local variable within a block, its scope is that block only. A local variable is active within the defining control block. The control block can be a procedure, an if statement, a loop statement and so on.
For more information on scope, see Scope.
Declaring Accessibility

.NET supports the idea of accessibility to variables, which allows you, the developer to control what code can access specific variables. For example if you wanted to set some constants for a formula and make sure that your constant never gets changed by other code outside of its class you could declare that variable private like this:

Private myConstant As Integer
Private int myConstant ;

A variable's accessibility is determined by which keyword or keywords—Dim, Public, Protected, Friend, Protected Friend, or Private—you use in the declaration statement. In general you will only use public and private in your development.

You can declare a module, structure, class, or instance variable with any of these keywords. Within a procedure, only the Dim keyword is allowed, and the accessibility is always private.

Code Sample 2. Variable declaration in c#.net
int head_count ;

string foo ;

Date X ;

object Obj ;

Wednesday, November 10, 2010

Migrating from PHP to ASP.NET- part2

Comparison

a comparison of some of the prominent features in PHP and ASP.NET.

1. Coding Language

PHP

C, C++ style scripting language with older ASP style mark up. Supports some OOP concepts.

ASP.NET

Supports more than 25 languages, but the 2 that are most-commonly used are Visual Basic .NET and C#. Most developers pick one language but can consume components written in any of the other supported languages.

2. Compiled Application Logic

PHP

Compilable and can be run as a executable

ASP.NET

Supported, in both dynamically-compiled and precompiled modes.

3. Full-Page Output Caching

PHP

No native support

ASP.NET

Supported, caches different versions of the page based on one or more URL parameters, browser type, a custom function, or any combination.

4. Partial-Page Output Caching

PHP

No native support

ASP.NET

Built-in support through use of User Controls. Data and other objects can be cached with sophisticated expiration rules using the Cache API.

5. Database Access

PHP

Has drivers for most databases on the market as well as open-source databases

ASP.NET

Supports OLE-DB and ODBC directly, and includes native drivers for Microsoft SQL Server™ and Oracle.

6. Database Output

PHP

Datasets are returned as PHP variables and can be outputted like any other variable

ASP.NET

Templated data binding to server-side controls for ease of development, or manual looping if that is preferred.

7. External Components

PHP

Can call a variety of packages and the Zend engine can be modified directly by the developer because it is open source. The programmers responsible for Zend are also working on allowing .NET objects to be called from PHP

ASP.NET

Very good support for native C libraries and COM objects, as well as assemblies written in any .NET-compliant language, including Managed C++. No built-in support for CORBA objects or Java classes.

8. XML/XSLT

PHP

Supported in add-on packages and libraries

ASP.NET

Comprehensive and easy-to-use support is provided for XML DOM, XSLT, validation, and lightweight stream-oriented parsing of XML documents.

9. XML Web Services

PHP

PHP packages are currently being developed to support Web services based on Apache AXIS engine as well as others.

ASP.NET

The current release provides extensive and flexible standards-compliant support and makes it extremely easy to both publish and consume Web services.

10. Session State

PHP

Cookie based session management

ASP.NET

Cookie-based or cookieless session state, using a single-server in-memory store, a centralized state server, or a database back-end. In addition, the extensible architecture allows for custom session-state modules to replace the built-in options. Cookieless sessions require only a configuration change to enable.

11. Built-In Functionality

PHP

PHP has built-in functions to cover many common tasks that a Web-based application may need to perform. It can also access Java class libraries with some extra work.

ASP.NET

ASP.NET has direct access to the entirety of the .NET Framework class libraries, which encompass a vast amount of functionality.

12. Regular Expressions

PHP

Supports POSIX and Perl compatible regular expression syntax.

ASP.NET

Supports Perl-5-compatible regular expressions, with additional features such as right-to-left matching, precompiled expressions, named groups, full Unicode support. Also allows the user to specify a function to be called during a regular expression replace operation.

13. Debugging

PHP

PHP does not offer extensive debugging, although various products from third parties and Zend allows for increased debugging and testing.

ASP.NET

Includes extensive tracing and environment information that can be included in the page or displayed in a separate page. Microsoft Visual Studio® .NET allows for easy interactive debugging of pages as they execute, in addition to debugging of client-side scripting and SQL Server stored procedures.

14. Error Handling

PHP

Does not support error trapping but has various error-handling functionality and logging,

ASP.NET

Supports structured exception handling (with the addition of a "finally" block for code that executes regardless of whether or not an error occurs), raising custom exceptions, and specifying custom error pages for different types of unrecoverable errors.

15. Image Manipulation

PHP

No built-in support, although third-party components are available.

ASP.NET

Includes extensive image creation and manipulation facilities. (See the .NET Framework's System.Drawing classes)

16. Code Re-Use

PHP

User-defined functions, ability to create Classes, and included files.

ASP.NET

User Controls, Server Controls, custom classes, and included files.

17. Threading

PHP

PHP has a good threading model

ASP.NET

Fully supported. Not only do simultaneous page requests happen in separate threads, but each page can (if needed) spawn its own threads to perform simultaneous or asynchronous work.

18. Data Caching

PHP

Has limited data native Data Caching

ASP.NET

Includes an extensive cache API that allows nearly any type of data (including database query results) to be stored, with expiration based upon time, usage, or dependency upon a file or another cached item. Also allows for a user-defined function to be called when a given item is removed from the cache.

19. Internationalization

PHP

Full support for Unicode

ASP.NET

Supports Unicode strings and various character encodings. Date, number, and currency functions are all culture-aware and alter their output depending on what the current culture is set to (rather than requiring different functions to be called). Support for using resource files to dynamically localize an application is included.

20. SMTP, HTTP, FTP, POP3

PHP

Native support for a wide variety of Internet protocols

ASP.NET

SMTP support depends upon the IIS SMTP Service. HTTP has very good support. FTP and POP3 are not supported in .NET, but free and commercial third-party components are available for this functionality.

21. Integrated Development Environment

PHP

Numerous development tools with a broad range of capabilities are available at price ranges from free to several hundred dollars.

ASP.NET

There is a free tool for ASP.NET development available from Microsoft called ASP.NET Web Matrix

The most popular tool is Visual Studio.NET which has full support for all .NET languages, database tools for creation of SQL and testing databases, Web Design tools, integration with version control, advanced debugging and numerous other features for a full list see the MSDN® Visual Studio Developer Center.

Other tools, including Borland C# Builder and Macromedia Dreamweaver MX, also support ASP.NET.

22. Web Server Support

PHP

Supports almost every Web server.

ASP.NET

Supports IIS and Covalent's commercial version of Apache 2.0.

23. Operating System Support

PHP

There are ports to almost every commonly used OS including Microsoft Windows®, Mac, OS X, Amiga, Solaris, Free BSD, Linux, AIX and more.

ASP.NET

Currently supports Windows 2000, Windows XP, and Windows Server 2003.