• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2921
  • Last Modified:

Conversion XML into Byte array

I need to "send up" a complex XML structure to a SOAP request.

The XML itself may have a couple of dozen tags nested a couple of levels deep.  It may even have a tag with bin64 encoded data (depends on the request).

I've seen code for reading a file into a Byte array and sending that to a server (in XML), but I've never seen code for converting XML into the same.  I'm looking for how to do this so I can make this soap request.
0
Gene Klamerus
Asked:
Gene Klamerus
  • 10
  • 5
1 Solution
 
Naveen SwamyYash Infinite Solutions Private LimitedCommented:
Dim memStre as MemoryStream = new MemoryStream(InternalGetDocument(name))

or to get the Document ...

public function GetDocument(byval name as string) as byte ()
      return InternalGetDocument(name)
end function

this might also help you

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21726205.html
http://www.experts-exchange.com/Web/Web_Languages/XML/Q_20796127.html
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20911498.html
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_21404956.html
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
This links are nice, but they mostly refer to creating binary XML elements, which we do already know.

The function MemoryStream looks interesting, but I don't see where InternalGetDocument() is documented anywhere.  I see that it may be a JavaScripting function, but we're using VB.Net (hence the question being in this forrum).

Let me clarify that my starting point is having a DOM in memory in a VB.Net application (or scripting in an ASP/ASPX).  I need to submit that as a SOAP request to the service (a SOAP service), as a single argument.

What I haven't seen anywhere is how to convert the DOM into a byte array or string (which we can easily convert between).
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
I've tried to make a more complete and thorough full description for this query.  This follows:

I need to "send up" a complex XML structure to a SOAP request from a VB.Net program.  It's also possible that we may need to do this from ASPX.

Either way, the program or page is the client to the server that we have and to which we need to upload the data.

The XML itself may have a couple of dozen tags nested a couple of levels deep.  It may even have a tag with bin64 encoded data (depends on the request).  We know how to create all this.

What we have had a struggling doing is finding out how to submit this to a web service (SOAP), but very recently someone suggested turning it into a byte array or string and sending it up as a single parameter.

This requires turning the XML structure into a byte array or string and returning it to an XML structure on the server.  We will do this in memory in a DOM.  We don't want to create a file just to upload.  That will have a performance impact.  We want to do this directly from the DOM structure in memory.

I've seen code for reading a file into a Byte array and sending that to a server (in XML), but I've never seen code for converting XML structure in a DOM in memory into a byte array or string.

I'm looking for how to do this so I can make this soap request.

Conversely I'd be interested in superior alternatives to this approach, but only something standard or very wide-spread (not DIME or WS-Attachment).
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Bob LearnedCommented:
1) Base-64 encoding:  

   Dim buffer() As Byte = Convert.FromBase64String(str)
   Dim str As String = Convert.ToBase64String(buffer)

2) Encoding:

   Dim buffer() As Byte = System.Text.Encoding.Utf8.GetBytes(str)
   Dim str As String = System.Text.Encoding.Utf8.GetString(buffer)

Bob
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
I just said I know how to convert between strings and byte arrays.  What I need is to convert from an in-memory DOM into either one or the other.
0
 
Bob LearnedCommented:
Words, words, words.  It is easy with all those words to miss something ;)

What do you mean by "convert from an in-memory DOM into either one or the other"?

Bob
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
I'm not sure how much more clearly to say it.  We all (I expect) create in memory XML structures.  DOM (Document Object Model) is one, but any XML structure will do.

An example of the XML structure I need to deal with follows.  I need to convert that (when in memory in an XML structure) into a string or byte array so that I can upload it via SOAP.

<?xml version="1.0"?>

<!DOCTYPE omdv-msg SYSTEM "omdv-msg-3_0.dtd">

<omdv-msg>

      <message-spec sender="ECOA-WEB-GLOBAL" correl-id="CERT_02885634.PDF" priority="PREMIUM" notify-type="ALL" notify-platform="NO">
            <status/>
            <status-text/>
            <beg-ts>30-Apr-2006 at 04:11:11 AM</beg-ts>
            <end-ts/>
            
            <sender-sig/>
            <notify-at>u383534</notify-at>
            <message-digest/>
            <current-service>1</current-service>
            <delegate-mailbox>FTNECOA</delegate-mailbox>
      </message-spec>
      
      <service-spec srvc-order="1" srvc-type="ARCHIVE" srvc-complete="NO" upon-failure="ABORT" notify-platform="NO" full-hdr="NO">
            <status/>
            <status-text/>
            <beg-ts/>
            <end-ts/>
            
            <archive-action>READ</archive-action>
            <docbase>ECOA01</docbase>
            <document-type>certificate_analysis</document-type>
            <select-attrib NAME="r_object_id">09002f188060a568</select-attrib>
      </service-spec>
      
      <service-spec srvc-order="2" srvc-type="FILTER" srvc-complete="NO" upon-failure="ABORT" notify-platform="NO" full-hdr="NO">      
            <status/>
            <status-text/>
            <beg-ts/>
            <end-ts/>

            <rem-log>NO</rem-log>
            <rem-water>NO</rem-water>
            <output-format ENCODING="PDF" PAPER-SIDES="SINGLE-SIDED" PAPER-SIZE="LETTER"></output-format>
      </service-spec>
      
      <service-spec srvc-order="3" srvc-type="EMAIL" srvc-complete="NO" upon-failure="CONTINUE" notify-platform="NO" full-hdr="NO">      
            <status/>
            <status-text/>
            <beg-ts/>
            <end-ts/>
            
            <reply-to>u383534</reply-to>
            <cover-block>ECOA/  HKYANGZI 2005-35/ NP-10</cover-block>
            <attachment-name>CERT_02885634.PDF</attachment-name>
            <to-addrs>lhou@dow.com</to-addrs>
      </service-spec>
      
      <service-spec srvc-order="4" srvc-type="ARCHIVE" srvc-complete="NO" fail-type="FAIL-CONTINUE" notify-platform="NO" full-hdr="NO">      
            <status/>
            <status-text/>
            <beg-ts/>
            <end-ts/>
            
            <archive-action>UPDATE</archive-action>
            <docbase>ECOA01</docbase>
            <document-type>certificate_analysis</document-type>
            <select-attrib NAME="r_object_id">09002f188060a568</select-attrib>
      </service-spec>

<payload>
Admin Allow v1.0 Jan 14, 1997 (public domain, no warranty!)
By Mike Ingle (inglem@adnetsol.com,inglem@std.teradyne.com)

Frequently NT administrators have files and directories that do not
allow Administrator access. This creates a problem for virus scans,
moving directories, user support, etc. Taking ownership is time-
consuming and breaks existing permissions.

This program modifies file permissions on NTFS files and directories
to allow Full Control for Administrators without breaking existing
permissions or taking ownership. Run it like:

admnalow d: e:
Affects all of D: and E: drives.
admnalow e:\users\joe
Affects only one directory (or file) and all subdirectories.

While running, the program prints a list of all files and directories
it has altered. It will also print any errors. It does not change files
that are already set correctly, so it will not turn your daily backup
into a total.

You can run this nightly before a virus scan or other automatic
operation from the scheduler, or run it as needed. It needs
administrator access, take-ownership, backup, and restore privileges.

How this program works:

The program turns on take-ownership, backup, and restore privileges.
Then it uses a findfirst/findnext loop to traverse the directories.
For each file or directory, it reads and inspects the ACL. If the ACL
does not give full control to administrators, or if it can't read the
ACL, it changes permissions on that file.

To do this, it first uses BackupRead to get the old owner of the file.
There is no politically correct way to do this without access to the
file that I know of, but the owner SID appears to be in a fixed location
in the data from BackupRead. In any case, the program checks the SID
and won't touch a file if it can't validate the SID.

Having read the old owner, it then sets owner to Administrator. It reads
the ACL, copies all ACEs not referring to Administrator to a new ACL,
and then adds ACEs giving administrator full control. Then it writes the
new ACL and sets the owner back as it found it. This leaves the file
permissions unchanged except for administrators having access.
</payload>

</omdv-msg>
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
Sometimes the payload portion of these XML structures will include a bin64 encoded PDF document, or word document, or image, etc.
0
 
Bob LearnedCommented:
1) Now that I understand the file structure, I need to fully understand the process, because I feel like I am missing an important piece.

2) Are you looking to serialize the entire XML document for a SOAP request?

3) Are you looking to extract parts of the document?

Bob
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
I'm looking to turn the entire thing into a byte array (which I have an example of submitting as a SOAP request).

If there's a different way of doing this (other than the byte array) I'm good with that.  The need is to upload this data as a SOAP request one way or another.
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
It looks like the following may work for me:

        Dim XmlDoc As New XmlDocument

        XmlDoc.Load("C:\Temp\Test1.xml")

        Dim TestText As System.String = XmlDoc.OuterXml

        RichTextBox1.Text = TestText

Or something like this.  I'm still working on it.
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
The loading was just to get me an XML in memory.  In reality, we're going to get the data from WebSphere MQ.
0
 
Bob LearnedCommented:
If you are just loading string text from a document, you don't need to use XmlDocument, you could just use a StreamReader or even RichTextBox.LoadFile.  I was struggling to understand what you meant.  I didn't realize that you were looking for something that simple.

Bob
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
As I said (somewhere), I'm currently loading the XML from a file to get the code working.  The data will be coming from a websphere MQ message.

What I need to do with it though is upload it to a web service.  So far as I know the code on the client (VB.Net) needs to match the code on the server (also VB.Net) both in number and type of parameter when doing ASP.Net web services (which I am).

I've heard that a byte array can be sent up because it will be a single parameter.  I just need to generate the byte array and interpret it at both ends.   On the client end, what I'll have is an XML structure (in memory) to start with.  That's also what I'll need to end up with on the server eventually.
0
 
Bob LearnedCommented:
Well, if you know how to read XML text, and how to convert strings to byte arrays, then what is your question?

Bob
0
 
Gene KlamerusTechnical ArchitectAuthor Commented:
I didn't know all of that when I posted this question (3-4 days ago).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 10
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now