1
votes

I've got a simple webservice developed in Progress 4GL from which I receive as output parameter a dataset with a blob in whoich I have stored a pdf file.

DEFINE TEMP-TABLE TTDocument                NO-UNDO
       FIELD DocSeqNr                       AS INT 
       FIELD FileName                       AS CHAR
       FIELD EventCode                      AS CHAR
       FIELD EventDescr                     AS CHAR
       FIELD FileContent                    AS BLOB 
       .


DEFINE DATASET ds FOR TTDocument.

DEFINE INPUT        PARAMETER pCoCd                         AS CHARACTER   NO-UNDO.
DEFINE INPUT        PARAMETER pLanCd                        AS CHARACTER   NO-UNDO.
DEFINE INPUT        PARAMETER pUsrCd                        AS CHARACTER   NO-UNDO.
DEFINE INPUT        PARAMETER pFilter                       AS CHARACTER   NO-UNDO.
DEFINE       OUTPUT PARAMETER DATASET                       FOR ds.
DEFINE       OUTPUT PARAMETER pErrorTxt                     AS CHARACTER   NO-UNDO.

In .Net I make a request to this web service and I handle the response like this :

       XmlElement doc;
       DataSet xxx = new DataSet();
       beaHostDB.GetDocumets(pCoCd, lanCd, pUsrCd,idAdd, out doc, out pErrorTxt);
       XmlElementToXmlDocment(doc);
       var reader = new StringReader(doc.InnerXml);
       xxx.ReadXml(reader);
       foreach (DataRow dr in xxx.Tables[0].Rows)
        {
                DcumentList.Add(new Document { FileContent =dr["FileContent"].ToString});
      }

So now I have a string with the binary representation of this pdf file.

How can I convert this string to bytes[] to get this pdf file in c#?

2
How is the file encoded in the XML response? There are methods to convert string to bytes[] likes Convert.FromBase64String - Luizgrs

2 Answers

0
votes

Probably it should be encoded using Base64 so you should go with the method Convert.FromBase64String:

 var byteContent = Convert.FromBase64String(dr["FileContent"].ToString())
0
votes

var test=(byte[])dr["FileContent"].ToString();