Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / March 2005

Tip: Looking for answers? Try searching our database.

XML Document through a web service

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Curt Krueger - 28 Feb 2005 22:34 GMT
Hello,
   Long day for me, so apologies in advance if I'm asking where the trees
are in the middle of the forest.

I have wrote a errorlog object that stores it's data in XML format.  What
I'm wanting to do is stream the XML through the web service, then to a
request made by ASP.NET.

I have successfully written one that will transmit it in binary format (see
code below), but what I'd like to is send it in its native format, XML plain
text.  The ASP.NET consumer could then either parse it, or simply offer up
saving to disk.

Regards,
Curt

======================
Any web pages/code examples to do the following, only in "text" or format?

public byte[] GetErrorLog()
{
   if (!File.Exists(LogPathAndFileName))
   return null;
   FileStream file = null;
   try
   {
     //ensures one thread has access at a time
       Monitor.Enter(this);
       file = new FileStream(LogPathAndFileName, FileMode.Open);
       byte[] fileStream = new byte[file.Length];
       file.Read(fileStream, 0, (int)file.Length);
       file.Close();
       return fileStream;
   }
   catch (Exception ex)
 {
        return null;
 }
finally
 {
     if (null != file)
     file.Close();
    Monitor.Exit(this);
 }
}
Dino Chiesa [Microsoft] - 01 Mar 2005 18:21 GMT
have your webservice return a System.Xml.XmlElement.  Something like the
following.

 [WebMethod]
 public System.Xml.XmlElement  GetElement()
 {
   System.Xml.XmlDocument doc= new     System.Xml.XmlDocument();
   doc.Load(TheFile);
   return doc.DocumentElement ;
 }

The webservice client will get an XmlElement, which can be loaded into an
XmlDocument, or saved, or transformed into an HTML table, or whatever.

-Dino

> Hello,
>    Long day for me, so apologies in advance if I'm asking where the trees
[quoted text clipped - 43 lines]
>  }
> }
Curt Krueger - 02 Mar 2005 16:17 GMT
Thanks for the help Dino.   What I didn't realize is that I can take this
byte stream and send it down to the browser in the same format.  As long as
I describe the content type in the response object, it automatically decodes
back to the original.  Here's the code that works for anyone that's
interested.

private void btnDownload_Click(object sender, System.EventArgs e)
 {
   byte[] fileStream = null;

  ErrorReporting er = new ErrorReporting(); // The web service call

  fileStream = er.GetErrorLog(out error);
  if (null != error)
    return;

  int length = fileStream.GetUpperBound(0) + 1;
  Response.Clear();
  Response.AddHeader("Content-Disposition", "attachment;
filename=errorlog.xml");
  Response.AddHeader("Content-Length", length.ToString());
  Response.ContentType = "application/octet-stream";
  Response.OutputStream.Write(fileStream, 0, length);
  Response.End();
 }

Works like a charm!

Regards,
Curt

> have your webservice return a System.Xml.XmlElement.  Something like the
> following.
[quoted text clipped - 11 lines]
>
> -Dino

> > ======================
> > Any web pages/code examples to do the following, only in "text" or format?
[quoted text clipped - 25 lines]
> >  }
> > }

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.