Try OpenEdge Now
skip to main content
.NET Open Clients
Using OpenEdge .NET Proxy Objects in Microsoft Visual Studio .NET : Using the samples
 

Using the samples

This section demonstrates using one of the .NET Open Client samples available in the Documentation and Samples directory. This sample application (written in VB.NET) is in the following location:
Doc_and_Samples_Install\src\samples\open4gl\dotnet\OrderInfo\
For more information on accessing and installing these samples, see the information on sample .NET client applications in Configuring and Deploying .NET Open Client Applications.
In this directory, you can find the following files:
*Demo.vb — VB.NET client source code
*OrderInfoDemo.sln — .NET Visual Studio solution file
*OrderInfoDemo.vbproj — .NET Visual Studio project file
*Readme.txt — Instructions on using the sample
Open the solution file provided, OrderInfoDemo.sln. You will see the reference for OrderInfo, the sample's ProxyGen-generated proxy assembly (OrderInfo.dll). You can look at the OrderInfo reference in the Object Browser. Expand this assembly, and you will see the following namespaces:
*OrderProxy
*OrderProxy.StrongTypesNS
OrderProxy is the General namespace you entered in the .NET Client Details group of the ProxyGen Generate Proxies dialog box. Under the OrderProxy namespace, you will see the OrderInfo and CustomerOrder classes for the AppObject and a ProcObject, respectively. Double-click on each class, to see the methods and properties available to your client.
For example, under the OrderInfo class are the four OrderInfo(...) constructors your client can call to create an OrderInfo instance. These are shown with a method name of New. You also will see the FindCustomerByName( ) method, which maps to its corresponding remote ABL method.
For proxies that contain methods with a static temp-table or static DataSet parameter, ProxyGen creates a namespace called namespace.StrongTypesNS, which contains the corresponding strongly typed DataTable and DataSet classes for that object. Here, namespace is the General namespace entered in the .NET Client Details group of the ProxyGen Generate Proxies dialog box, or it may be omitted. In this example, the namespace is OrderProxy.StrongTypesNS.
If you expand the OrderProxy.StrongTypesNS namespace, you will see, for example, the OrderDetailsDataTable class. This is the strongly typed DataTable class created by ProxyGen for the static temp-table definition OrderDetails. You use this class in your client application when calling the corresponding AppServer method that has the static temp-table parameter. You can expand the OrderProxy.CustomerOrder class and examine the signature of the GetOrderDetails(..) and UpdateOrderDetails(..) methods. Both these methods contain parameters of the OrderProxy.StrongTypesNS.OrderDetailsDataTable class.
Microsoft Visual Studio .NET IntelliSense provides easy access to these objects when you write your client application in the text editor. If you type the namespace of the class (for example OrderProxy.), the following list of objects (in this example, in the OrderProxy namespace) is displayed:
*OrderInfo (class)
*CustomerOrder (class)
*StrongTypesNS (nested namespace)
You can select the desired class or member and easily add it to your code.
Open the client source file, Demo.vb. This is the sample client code that accesses the proxy classes. First, notice that the client code creates variables for each of the proxy objects, as shown:
' Declare the proxy objects
Dim m_conn As Connection = Nothing
Dim m_order As OrderInfo = Nothing
Dim m_custOrder As CustomerOrder = Nothing
Dim m_custOrderDetails As StrongTypesNS.OrderDetailsDataTable = Nothing
In the subroutine for the Connect button click, btnConnect_Click, there is the code to establish the connection to the AppServer. This code creates a connection object and then passes that object into the constructor for the AppObject, OrderInfo. This code is written within a try...catch block, because a connection failure will be returned as an exception from the Open Client Runtime, as shown:
Try
   ' Instantiate the proxy objects and connect
   m_conn = New Connection(txtURL.Text, "", "", "")
   m_order = New OrderInfo(m_conn)
   .
   .
   .
Catch conEx As Exception
   .
   .
   .
End Try
In the subroutine for the Search button, btnFindByNum_Click, you will find the code to run the non-persistent procedure FindCustomerByNum. This runs the procedure on the AppServer using the connection already established. Again the proxy call is written inside a try...catch block, as shown in the following code:
' This finds a Customer Name from the Customer Number
Dim custNum As IntHolder = New IntHolder( )
Dim custName As String = Nothing

Try
   ' Send a request to the AppServer to get the Customer Name
   m_custNum = CInt(txtCustNum.Text)
   custNum.Value = m_custNum
   m_order.FindCustomerByNum(custNum, custName)
   .
   .
   .
Catch procEx As Exception
   .
   .
   .
End Try
Now the client code executes a persistent procedure on the AppServer, passing it the customer number obtained from the call to the non-persistent procedure above. After the code creates the ProcObject for the persistent procedure, it calls a method on the ProcObject, GetOrderDetails, which executes the corresponding internal procedure in the persistent procedure on the AppServer. In both cases, the code is written inside a try...catch block, as shown:
' Run CustomerOrder.p on the AppServer
m_custOrder = m_order.CreatePO_CustomerOrder(custNum)
m_custOrder.GetOrderDetails(m_custOrderDetails)
   .
   .
   .
Finally, the client code must disconnect from the AppServer. This code can be found in the subroutine for the Disconnect button, btnDisconnect_Click. Again the proxy calls are written inside a try...catch block, as shown in the following code:
Try
   ' Tell the AppServer to release the Persistent Proc
   If Not (m_custOrder Is Nothing) Then
      m_custOrder.Dispose( )
   End If
   m_order.Dispose( )
   .
   .
   .
Catch relEx As Exception
   .
   .
   .
End Try