What's wrong with doing this?

Discussion in 'ASP .Net Web Services' started by MikeL, Feb 17, 2005.

  1. MikeL

    MikeL Guest

    I need to get the XML doc from the deserialized type (seResults) returned
    from a web service. Here's what I came up with - thanks in advance:

    System.Xml.Serialization.XmlSerializer s = new
    System.Xml.Serialization.XmlSerializer(typeof(seResults));
    // First, get the size of the result XML doc and initialize the byte array:
    Stream mm = new MemoryStream();
    s.Serialize(mm, results);
    byte[] byteArray = new byte[mm.Length];
    mm = new MemoryStream(byteArray,0,(int)mm.Length);
    // Now serialize the result:
    s.Serialize(mm, results);
    // Now convert it to a string:
    ASCIIEncoding encoding = new ASCIIEncoding( );
    string str = encoding.GetString(byteArray);
    str = str.Trim();
    MessageBox.Show(str);
     
    MikeL, Feb 17, 2005
    #1
    1. Advertisements

  2. MikeL

    MikeL Guest

    Here's better code (I originally didn't see the GetBuffer function):

    System.Xml.Serialization.XmlSerializer s = new
    System.Xml.Serialization.XmlSerializer(typeof(seResults));

    // First, get the size of the result XML doc and initialize the byte array:
    MemoryStream mm = new MemoryStream();

    // Now serialize it:
    s.Serialize(mm, results);

    // Now convert it to a string:
    ASCIIEncoding encoding = new ASCIIEncoding( );
    string str = encoding.GetString(mm.GetBuffer());
    str = str.Trim();
    MessageBox.Show(str);
     
    MikeL, Feb 17, 2005
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.