Upload
adela-gibbs
View
213
Download
1
Embed Size (px)
Citation preview
Cross-Language Demo
Demonstrates mixing C# and VB.NET code
C# Class CSDemoClass.cs
VB.NET Class VBDemoClass.vb
“Main” class (C#) Demo.cs
CSDemoClass.cs
using System;
namespace CSDemo {public class CSDemoClass {
… protected String getDateTime(){ return DateTime.Now.ToString(); }}
}
VBDemoClass.vb
Public Class VBDemoClass
Public Sub ShowTime(ByVal time as String)MsgBox(time, MsgBoxStyle.Information,
“VB MsgBox”)End Sub
End Class
Demo.cs
using System;using CSDemo;using VBDemo;
namespace Demo {class Demo {
static void Main(string[] args) { String date;
CSDemoClass csApp = new CSDemoClass(); VBDemoClass vbApp = new VBDemoClass();
date = csApp.getTime(); vbApp.ShowTime(date);
}}
}
Cross-Language Example
Using .NET
Jiunwei Chen
ASP.NET
Evolution of ASP (Active Server Pages) Traditional web scripting language
Features Use any .NET language (C#, VB, COBOL, etc) Compiled and executed in native machine code Allows for code-behind Objected-oriented web development environment Web Forms and Web Services
Network
Managed Process
ASP.NET
Hosting the .NET Framework CLRWeb form
and custom application objects
Request and post-back form information
HTML representation of application UI
Web Server
Bro
wse
r-C
lien
tASP.NET in Context
Code Behind
Separation of the HTML and the code Markup resides in an .ASPX file Code lies in a C# (.CS) file or managed assembly
(.DLL)
ASP.NET Class is derived from System.Web.UI.Page HTML is generated and sent to the browser
Time.aspx<% @Page Language="C#" Inherits=“TimePage" Src=“Time.cs" %>
<html><body> <TITLE>Time Page</TITLE> <H1 align="center"> The time is <% OutputTime();%> </H1></body></html>
Time.cs
using System;using System.Web.UI;
public class TimePage:Page{ protected void OutputTime(){ Response.Write( DateTime.Now.ToString(“T")); }}
Time Example
Web Forms
Core of ASP.NET Separates interface from code logic (View /
Model) ASP.NET detects browser and chooses rendering
Server-side controls Can use visual tools to layout controls Similar to VB, JavaBeans, WebObjects
WebControls.aspx
<% @Page Language="C#" Inherits="DatePage" … %>
<html> ... <Form method="post" runat="server"> ... <asp:Calendar id="calendar" runat="server"> </asp:Calendar> <asp:TextBox id="date"
runat="server"/><br> <asp:Button id="button" Text=“Submit" runat="server"></asp:Button> ...
Web Controls Example
XML Web Services
Small, re-usable application components shared over the Web as services
XML data representation
HTTP transport protocol
SOAP (Simple Object Access Protocol) RPC (Remote Procedure Call) standard
Network
Managed Process
ASP.NET
Hosting the .NET Framework CLRXML Web
Service objects
SOAP MethodRequest
SOAP MethodResponse
Web Server
Ser
vice
-Cli
ent
XML Web Services
Why use XML Web Services?
Faster Development Use any .NET language XML naturally separates data from view “.NET My Services” provides core functions (user
authentication, etc.) Greater Reliability
Harness all the benefits of the CLR Integration
Built off XML and SOAP
References
Clark, Jason, .NET Tutorials, 2001 (Accessible at www.devhood.com)
Microsoft Corporation, Microsoft.NET, http://www.microsoft.com/net/, 2002