System.Byte[ ] - RAW not accepted...

Posted by dbeattie on 09-Jul-2009 09:04

I'm having difficulty with a method in a .NET object I'm trying to use in 10.2A01.

The method is UploadData(INPUT CHARACTER, INPUT CHARACTER, INPUT System.Byte[]) - System.Net.WebClient Returns System.Byte[]  value.

I tried to call the method using the following ABL syntax (the Progress documentation says System.Byte[] translates to RAW and doesn't allow me to define a variable of type System.Byte):

DEFINE VARIABLE rRaw AS RAW NO-UNDO.

DEFINE VARIABLE rResult AS RAW NO-UNDO.

rResult  = myWebClient:UploadData(cURL, "POST":u, rRaw).

I get the following error:
Could not locate method 'UploadData' with matching signature in class 'System.Net.WebClient'. (14457)

I eventually got around this by making the following call:

DEFINE VARIABLE iPost   AS INTEGER EXTENT.
DEFINE VARIABLE iResult AS INTEGER EXTENT.

iResult  = myWebClient:UploadData(cURL, "POST":u, iPost).

However iResult and iPost are a pain to work with compared to the LOBs the ABL offers.

Has anyone else run into this issue? Have you resolved it a better way?

Thanks,

Don.

All Replies

Posted by Matt Baker on 09-Jul-2009 09:29

You can use this syntax to define a byte array.

define variable x as "System.Byte[]" no-undo.

x = new "System.Byte[]" (20).

Posted by dbeattie on 09-Jul-2009 10:32

That work for me, thanks. But how do I work with a variable of that type.

For example I was able to set the size:

ASSIGN bRequest = NEW "System.Byte[]" (LENGTH(myXMLfile)).

However, if i wanted to use it as a return value and didn't know the length how would I define it? Using (0)?

Also, how to you set the value? I get casting errors when attempting to put a longchar or string, and other errors when trying to use raw, etc?

Thanks,

Don.

Posted by Matt Baker on 09-Jul-2009 10:58

The syntax as above creates an object that is a System.Byte array.  It is not an ABL extent variable.  You can treat it like an instance of the object System.Array.  It will have all the properties of System.Array.  Therefore you can use the method SetValue() and property Length.

Note that you need to use unsigned bytes when assigning values since System.Byte maps to ABL unsigned byte.

define variable x as "System.Byte[]" no-undo.
x = new "System.Byte[]" (20).

x:SetValue(16 as unsigned-byte, 2).

message x:getvalue(2) view-as alert-box.

You won't be able to assign a string value to it because 1) it is an array and 2) because you have code page issues you need to deal with.  If you are using a multi-byte code page then the individual characters in your string or longchar variable may expand out to more than a single byte.  You need to first convert your longchar to bytes and then call the method.  Here is how to use the .NET classes to do it in ABL.

define variable x as "System.Byte[]" no-undo.
define variable textEncoding as System.Text.Encoding no-undo.


/* this needs to be based on the contents of your xml document
  usually utf8 ot utf16 */
 
textEncoding = System.Text.ASCIIEncoding:UTF8.

/* convert the string to bytes */

x = textEncoding:GetBytes("my real long string").

/* show the length */
message x:length view-as alert-box.

This thread is closed