CREATE NETOBJECT Example


Example 1:

 

DATETIME

NETOBJECT

 

ccyy

INTEGER

2,"2007"

mm

INTEGER

2,"6"

dd

INTEGER

2,"2"

h

INTEGER

2,"14"

m

INTEGER

2,"25"

s

INTEGER

2

*

 

 

.Create the Object

.

 

 

 

CREATE

DateTime,CLASS="System.DateTime",Assembly="mscorlib":

 

 

*$=ccyy,*$=mm,*$=dd,*$=h,*$=m,*$=s

.

 

 

 

DateTime.ToString GIVING S$CMDLIN

.

 

 

 

DISPLAY

"DATETIME:",*LL,S$CMDLIN,*W10

 

Example 2:

 

 

INCLUDE

PLBEQU.INC

.

 

 

FileModeCreate

NETOBJECT

 

FileModeOpen

NETOBJECT

 

BoolTrue

VARIANT

 

BoolFalse

VARIANT

 

AutoTrue

INTEGER

4,"0xffffffff"

DATA

DIM

1024

.

 

 

 

CREATE

BoolTrue,VarType=11,VarValue=AutoTrue

 

CREATE

BoolFalse,VarType=11,VarValue=0

*

 

 

.The FileModeXXXX NETOBJECTs are created from a FileMode Enumeration.

.

 

 

 

CREATE

FileModeCreate:      ;FileMode Enumeration for Create const

 

 

CLASS="System.IO.FileMode:Create":

 

 

Assembly="mscorlib"

.

 

 

 

CREATE

FileModeOpen:      ;FileMode Enumeration for Open const

 

 

CLASS="System.IO.FileMode:Open":

 

 

Assembly="mscorlib"

.

 

 

 

DISPLAY

"NetSoap NETOBJECT Demo",*N

.

 

 

 

CALL

Serialize

 

CALL

Deserialize

.

 

 

 

LOOP

 

 

EVENTWAIT

 

 

REPEAT

 

*

 

 

.Serialization Function

.

 

 

Serialize

FUNCTON

 

 

ENTRY

 

Addresses

NETOBJECT

;Hashtable object

FS

NETOBJECT

;FileStream object

Formatter

NETOBJECT

;SOAP formatter object

.

 

 

 

DISPLAY

"*********************************************************":

 

 

*N,"Netsoap: Serializer Started"

*

 

 

. Create a hashtable of values that will eventually be serialized.

.

 

 

 

EXCEPTSET

SerializeError IF OBJECT

 

CREATE

Addresses,CLASS="System.Collections.Hashtable":

 

 

Assembly="mscorlib"

.

 

 

 

Addresses.Add Using "Jeff", "123 Main Street, Redmond, WA 98052"

 

Addresses.Add Using "Fred", "987 Pine Road, Phila., PA 19116"

 

Addresses.Add Using "Mary", "PO      Box 112233, Palo Alto, CA 94301"

*

 

.To serialize the hashtable (and its key/value pairs), you must first open

. a stream for writing.

.

 

 

 

CREATE

FS:            ;File stream used for output

 

 

CLASS="System.IO.FileStream":

 

 

Assembly="mscorlib":

 

 

*$="c:\temp\netsoap.soap":

 

 

*$=FileModeCreate      

*

 

 

.Construct a SoapFormatter and use it to serialize the data to the stream.

.

 

 

 

CREATE

Formatter:

 

 

CLASS="System.Runtime.Serialization.Formatters.Soap.SoapFormatter":

 

 

Assembly="System.Runtime.Serialization.Formatters.Soap"

*

 

 

.The data from the Addresses Hashtable is streamed into the FS file stream

. in a SOAP format.

.

 

 

 

Formatter.Serialize USING FS, Addresses

 

FS.Close

 

 

EXCEPTCLEAR OBJECT

 

DISPLAY

"Netsoap: Serializer create 'c:\temp\netsoap.soap' file!":

 

 

*N,"*********************************************************"

 

RETURN

 

.

 

 

SerializeError

 

 

DISPLAY

"S$ERROR$:",*LL,S$ERROR$,"<<<",*N

 

GETINFO

EXCEPTION,DATA

 

DISPLAY

*WRAPON,DATA

.

 

 

 

FUNCTIONEND

 

*

 

 

.Deserialize Function

.

 

 

DeSerialize

FUNCTION

 

 

ENTRY

 

Addresses

NETOBJECT

 

FS

NETOBJECT

 

Formatter

NETOBJECT

 

FileModeCreate

NETOBJECT

 

DE

NETOBJECT

 

IENUM

NETOBJECT

 

.

 

 

CNT

FORM

3

I

FORM

3

F3

FORM

3

KEY

DIM

20

Value

DIM

50

.

 

 

 

DISPLAY

*N,"*********************************************************":

 

 

*N,"Netsoap: DeSerializer Started"

 

EXCEPTSET

DeSerializeError IF OBJECT

*

 

 

.Declare a hash table reference.

.

 

 

 

CREATE

Addresses,CLASS="System.Collections.Hashtable":

 

 

Assembly="mscorlib"

*

 

 

.Open the file containing the data that you want to deserialize.

.

 

 

 

CREATE

FS:                        ;File stream used for input

 

 

CLASS="System.IO.FileStream":

 

 

Assembly="mscorlib":

 

 

*$="c:\temp\netsoap.soap":      ;SOAP data file to be opened

 

 

$=FileModeOpen            ;FileMode.Open

*

 

 

.Construct a SoapFormatter and use it to deserialize the data.

.

 

 

 

CREATE

Formatter:

 

 

CLASS="System.Runtime.Serialization.Formatters.Soap.SoapFormatter":

 

 

Assembly="System.Runtime.Serialization.Formatters.Soap"

*

 

 

.Deserialize the Hashtable from the file and assign the reference to the local variable.

.

 

 

 

Formatter.Deserialize GIVING Addresses Using FS

 

DISPLAY

Netsoap: DeSerializer has read      'c:\temp\netsoap.soap' file."

*

 

 

.To prove that the table deserialized correctly, display the key/value

. pairs to the Main Window.

.

 

 

 

GETPROP

Addresses, *Count=CNT

 

DISPLAY

"Hashtable Pair Count:",CNT,*N

.

 

 

 

Addresses.GetEnumerator GIVING IENUM

.

 

 

 

FOR

I,1,CNT

 

I IENUM.MoveNext GIVING F3

 

IENUM.get_Current GIVING DE

 

BREAK

IF (F3 == 0)

 

GETPROP

DE,*Key=KEY

 

GETPROP

DE,*Value=VALUE

 

DISPLAY

I:",I,"...KEY:",*LL,KEY,"...VALUE:",*LL,VALUE,"<<<"

 

REPEAT

 

.

 

 

 

DISPLAY

*N,"Netsoap: DeSerializer Completed":

 

 

*N,"*********************************************************"

.

 

 

 

RETURN

 

.

 

 

DeSerializeError

 

 

DISPLAY

"S$ERROR$:",*LL,S$ERROR$,"<<<",*N

 

GETINFO

EXCEPTION,DATA

 

DISPLAY

*WRAPON,DATA

.

 

 

 

FUNCTIONEND

 

 

This program was derived from a sample program demonstrated by the Microsoft MSDN documentation for the 'SoapFormatter Class'. It demonstrates the following basic operations using NETOBJECT:

  1. Creates .NET Enumerator Constants.

  2. Creates .NET Hashtable object.

  3. Creates .NET FileStream objects.

  4. Creates .NET SOAP formatter object.

  5. Executes .NET SOAP serializer to create a SOAP message that contains the Hashtable object data.

  6. Executed .NET SOAP deserializer to retrieve Hashtable data from a SOAP message.

  7. Demonstrates logic that can process throw the members of an IDictionaryEnumerator that iterates through the Hashtable data pairs.



PL/B Language Reference