Getting Started with Microsoft .NET for IBM i Developers
Craig Pelkie
[email protected] Copyright © 2014, Craig Pelkie ALL RIGHTS RESERVED
What does the .NET Framework “buy you”? • Comprehensive development environment • Many commonly needed resources are built into the framework • Windows programming • Web programming • Web services • Database • XML
• Consistent object model • The .NET Framework is supplied / supported by Microsoft • Commonly used base data types, low-level code • Supporting classes • Exception handling
2
Microsoft Programming Languages for .NET • C++ • Primary development language for most Windows system programming • Can be used in .NET environment
• F# • Functional Language • See wikipedia.org article, “F Sharp (programming language)”
• Visual Basic • Long history as an easy-to-use, applications-oriented tool • Visual Basic.NET: completely new version of language • Is a full O-O programming language with complete access to the .NET environment
• C# (C-sharp) • New language, introduced with .NET • Characteristics of C, C++, Java 3
Factors to Consider • Most RPG programmers are more comfortable with Visual Basic • Programmers with Java / C experience will be more comfortable with C# • Biggest Factor • As you get up-to-speed with .NET development • The "fear" of the language is less emphasized • Knowledge of and usage of .NET Framework classes moves to the foreground
The Language .NET
Time / Experience
The Language
.NET 4
Tools for Application Development • .NET 4.5 • Framework supports Web, Windows, Database, other commonly required features • Supports many programming languages, most popular: C#, Visual Basic • No-charge download (run-time environment, tools, compilers)
• Visual Studio • Current version is Visual Studio 2013 • Several editions • Express Editions (VB, C#, Web) • Professional Edition (includes all languages/features)
• “The 3 W's” • WCF — Windows Communication Foundation • WPF — Windows Presentation Foundation • WF — Windows Workflow Foundation
5
Development Environment – Visual Studio Obtaining Microsoft Visual Studio products Visual Studio 2013 Professional Edition – 90 Day Trial http://www.visualstudio.com/downloads/download-visual-studio-vs
Visual Studio Express 2013 No-charge downloads 30 day trial Requires registration for continued use
6
Platform to Platform
IBM i
.NET
Messaging
Web Services / WCF WebSphere MQ – MSMQ Data Queues
Messaging
Programs
Stored Procedures OLE DB API (cwbx)
Programs
Database
.NET Provider OLE DB Provider ODBC
Database
File System
FTP Network Drive
File System
7
Connection Options from .NET to IBM i • The problem, in a nutshell: • Database is on IBM i • .NET applications need to access the data • Extensive support in .NET Framework for database • Built-in support for SQL Server, Oracle
• .NET to IBM i – Database Providers • Components that are designed for .NET or can be used within .NET • Handle database specific issues • EBCDIC conversion • Packed/Zoned • Access to metadata
8
Connection Options, IBM i Access for Windows • IBM i Access for Windows • Licensed Program Products • 57xx-XW1 – IBM i Access Family
Provider
System i Access VRM
ODBC
V5R1+
OLE DB
V5R1+
.NET
V5R3+
• 57xx-XE1 – IBM i Access for Windows • These providers are no-charge components of IBM i Access • Can be installed independently of other IBM i Access components
9
Notes about System i Access Providers • ODBC, OLE DB • No special considerations • Accessed through .NET classes in • System.Odbc • System.OleDb • Not the preferred providers for .NET applications
• .NET Data Provider • Available starting at System i Access V5R3M0 • Can connect to down-level OS/400 versions • Must have .NET Framework already installed on PC • Not automatically installed when upgrading System i Access, must use Selective Install option • Critically important to update to current IBM Service Pack
10
Data Reader Example - Visual Basic
'create the connection object to connect to iSeries Dim cn As New iDB2Connection("DataSource=host_name") cn.Open()
'create a command object and initialize it to a valid SQL statement Dim cmd As New iDB2Command("select * from library_name.qcustcdt", cn)
'create a data reader object, fill it by executing the command Dim dr As iDB2DataReader dr = cmd.ExecuteReader() 'iterate over the data reader, write out values for each row/column
While (dr.Read()) Dim I As Integer
For I = 0 To dr.FieldCount – 1 Console.Write(dr.GetName(i))
FieldCount – actual number of fields returned in SELECT FieldCount – 1 : upper limit of loop (counter starts at zero)
Console.Write(":" & vbTab)
Console.WriteLine(dr.GetValue(i)) Next Console.WriteLine("-------------------------------------") End While
11
Data Reader Example - C#
// create the connection object to connect to iSeries iDB2Connection cn = new iDB2Connection("DataSource=host_name"); cn.Open(); // create a command object and initialize it to a valid SQL statement iDB2Command cmd = new iDB2Command("select * from library_name.qcustcdt", cn); // create a data reader object, fill it by executing the command iDB2DataReader dr; dr = cmd.ExecuteReader(); // iterate over the data reader, write out values for each row/column
while (dr.Read()) {
for (int i = 0; i < dr.FieldCount; i++) { Console.WriteLine("{0}:\t{1}", dr.GetName(i), dr.GetValue(i));
FieldCount – actual number of fields returned in SELECT i < FieldCount : upper limit of loop (counter starts at zero)
} Console.WriteLine(new String('-', 50)); }
12
Microsoft Web Development • Based on ASP.NET • Early web technology (pre-.NET): Active Server Pages (ASP) • Mix of HTML / CSS / VBScript or JScript
• .NET Framework 1.0 • • • •
Introduction of ASP.NET Separation of presentation / code ("code behind") Many server-side controls to generate HTML Visual Basic or C#
• ASP.NET MVC • • • •
Introduced in .NET 3.x timeframe "3-tier" web development environment More oriented towards HTML/JavaScript/CSS "Razor" syntax (inline substitution variables)
13
Web Development in Visual Studio 2010
14
Web Development in Visual Studio 2010
15
Display data with the GridView control
The GridView control is included in the Data section of the Toolbox The GridView is bound to a datasource to get data to display
16
Visual Studio Toolbox for Web Development The Toolbox is typically displayed on the left side of Visual Studio. You drag-and-drop a tool onto the design surface. You set properties at design-time or in your code.
17
Develop a Web Service in Visual Studio
18
Web Services code to return data
SelectCustomer web method Input: customer # Output: DataSet (record) for the customer
19
Output of the Web Service that returns data
20
Consume a Web Service in Visual Studio
2
1
3
In a project, use Add Service Reference
4
5 21
Consume a Web Service in Visual Studio
22
Deploying .NET applications for the IBM i
Development PC
Web Users
VS2013
IBM i Access OLE DB / .NET Provider
Development Built-in IIS Express
Deploy from Visual Studio
IBM i Server
IIS 6 / 7 / 7.5 / 8 (web application)
IBM i Access OLE DB / .NET Provider
DB2 UDB Microsoft .NET Server W2012 / W2008 / W2003 23
Deploying .NET applications for the IBM i • .NET applications are deployed on a Windows Server system that hosts the IIS Web Server • Microsoft Windows 2012 / 2008 R2 server / Windows 2008 • Microsoft Windows 2003 R2 Server • Can be deployed on: • Windows XP Professional • Windows Vista Business / Windows Vista Ultimate • Windows 7 Professional +
• Visual Studio is usually not installed on a production server • May need to obtain / install .NET Framework run-time environment for the server • Available from Microsoft Update web site • .NET Framework (2.0, 3.0, 3.5, 4.0, 4.5)
24
Deploying .NET applications for the IBM i • Microsoft .NET web applications run under Microsoft Internet Information Services 6.0 (W2003) 7.0 / 7.5 (W2008/2008R2) 8.0 (W2012) • To do: become familiar with IIS configuration • Copy/Publish all files for your Web application from development PC to the server (Visual Studio Publish Web Site tool) • Reference web site: www.iis.net
• The IBM IBM i Access provider(s) must be installed on the Windows Server • OLE DB provider and/or .NET provider • Install the current IBM i Access Service Pack • Perform periodic IBM i Access Service Pack installs on server • Verify that Service Pack levels on the development PC and the server are the same before deploying an application
25
Resources www.microsoft.com/visualstudio www.microsoft.com/net www.iprodeveloper.com Microsoft .NET for IBM i Developers Track 1 - Getting Started (VS, DB providers, language [VB, C#] Track 2 - ASP.NET Web Development Track 3 - ASP.NET and WCF Services
iProDeveloper eLearning course Begins Wednesday March 26, 2014 Exclusive discount for User Group members http://iprodeveloper.com/microsoft-net-ibm-i-developers-track-1-exclusive-discount?promo=EP14609 26