6/5/2009 1 Using .NET classes in PowerBuilder PowerBuilder Developers are .NET Developers! Donald D. Clayton [email protected]Agenda • Overview of .NET • Overview of PB .NET • Using .NET features in PowerBuilder • Translating C# code snippet to PowerScript • Consuming Web Services using .NET interop
26
Embed
Using .NET classes in PB.ppt - SAP Users' Group of …€¦ · • Can’t define a PowerBuilder class that implements a .NET interface • .NET classes, interfaces and enums can’t
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
6/5/2009
1
Using .NET classes in PowerBuilderPowerBuilder Developers are .NET Developers!
An interface defines a contract• Interfaces don’t contain implementation.• Classes that implement the interface implement the contract.• No static members in interfaces
Three kinds of arrays• Single-dimensional arrays• Multidimensional arrays• Jagged arrays (array of arrays)
All .NET arrays are of type System.Array• All .NET arrays can be accessed using the System.Array class
By default, indices of .NET arrays starts from 0
Using Single-dimensional .NET Arrays
• Declare an array and assign the return value to it
.NET function of class Company: public string[] getEmployees(int department)
PowerScript code:int iString employees[]Employees = l_company.getEmployees(departmentId)For i = 1 to upperBound(employees)lb_1.addItem(employees[i])
next
6/5/2009
15
Using Multidimensional .NET Arrays
• Difference between .NET arrays and PB arrays– In .NET, the last dimension is the fastest-varying dimension– In PB, the first dimension is the fastest-varying dimension
.NET function: public int[][] getJaggedArray()PowerScript code:long i, j, kSystem.Array arr1, arr2arr1 = obj.getJaggedArray() // obj is a .NET objectfor i = arr1.getLowerBound(0) to arr1.getUpperBound(0)arr2 = arr1.getValue(i)for j = arr2.getLowerBound(0) to arr2.getUpperBound(0) k = arr2.getValue(j)…next
next
6/5/2009
18
Creating a Jagged .NET Array
System.@Type tt = [email protected]("System.Int32[]")System.Array mama = System.Array.CreateInstance(t, 4)
• Can’t define a PowerBuilder class that inherits from a .NET class• Can’t define a PowerBuilder class that implements a .NET interface• .NET classes, interfaces and enums can’t be used as function
parameters or return types.– Can’t use delegates that have parameters
Generating PB proxy for Web services• Use wsdl.exe to generate .NET proxy class• Use csc.exe (C# compiler) to compile the .NET proxy class• Write PB proxy for .NET proxy class
Wsdl.exe csc.exe Writing PB proxy
.wsdl .cs .dll PB NVO
Steps for generating PowerBuilder proxies for Web services
6/5/2009
23
Advantages of Using .NET interop
• No data marshalling between managed and unmanaged worlds• Able to deal with array of arrays or multidimensional arrays
Using GoogleSearchService
• Download wsdl file from http://api.google.com/GoogleSearch.wsdl. • Generate C# code
• Use .NET Reflector to examine the classes• Look for samples to see how to use the classes• Write PowerBuilder proxies
6/5/2009
24
Demo - GoogleSearch
.NET Reflector
Download from http://www.aisto.com/roeder/dotnet/
6/5/2009
25
Creating PowerBuilder Proxies
• Create an NVO for each .NET class– E.g. n_googleSearchService– Declare an instance variable of the .NET type to be wrapped.
• Write a function for each .NET function you want to call– doGoogleSearch– Map parameter types and return type– Call the .NET function in .NET code block
• Write a getter and/or setter for the .NET property or field you want to access
• If the return type is a jagged array, create a PowerBuilder proxy for the array.
Creating PowerBuilder Proxies
//function n_GoogleSearchResult doGoogleSearch(…)n_GoogleSearchResult result