Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Passing a xml document to and from a web service...

Passing a xml document to and from a web service...

Scheduled Pinned Locked Moved C#
csharpxmlhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Manster
    wrote on last edited by
    #1

    Hi, I'm trying to create a C# web service that takes a string (a file path) and returns the xml document. I'm having some trouble with this task so any help would be much appreciated. If you know of any examples that do this, please share them. My web service function looks like this: [WebMethod(Description = "Returns the xml file.")] public XmlDocument GetXmlFile( string sXmlFilePath ) { if( sXmlFilePath != "" || sXmlFilePath != null ) { m_XmlDocument.Load( sXmlFilePath ); m_XmlDocument.Save( @"C:\Documents and Settings\dsterling\Desktop\Golfers311.xml" ); } return m_XmlDocument; } m_XmlDocument is a global variable. Below is the code in my web service consumer app. private void button1_Click(object sender, System.EventArgs e) { XmlNode xNode = TWS.GetXmlFile( @"C:\Documents and Settings\bob\Desktop\Golfers.xml" ); xDoc.Load( @"C:\Documents and Settings\bob\Desktop\Golfers.xml" ); xDoc.Save( @"C:\Documents and Settings\bob\Desktop\Doug.xml" ); System.Diagnostics.Process.Start( "notepad.exe", @"C:\Documents and Settings\bob\Desktop\Doug.xml" ); } Thanks for your help!

    H 1 Reply Last reply
    0
    • M Manster

      Hi, I'm trying to create a C# web service that takes a string (a file path) and returns the xml document. I'm having some trouble with this task so any help would be much appreciated. If you know of any examples that do this, please share them. My web service function looks like this: [WebMethod(Description = "Returns the xml file.")] public XmlDocument GetXmlFile( string sXmlFilePath ) { if( sXmlFilePath != "" || sXmlFilePath != null ) { m_XmlDocument.Load( sXmlFilePath ); m_XmlDocument.Save( @"C:\Documents and Settings\dsterling\Desktop\Golfers311.xml" ); } return m_XmlDocument; } m_XmlDocument is a global variable. Below is the code in my web service consumer app. private void button1_Click(object sender, System.EventArgs e) { XmlNode xNode = TWS.GetXmlFile( @"C:\Documents and Settings\bob\Desktop\Golfers.xml" ); xDoc.Load( @"C:\Documents and Settings\bob\Desktop\Golfers.xml" ); xDoc.Save( @"C:\Documents and Settings\bob\Desktop\Doug.xml" ); System.Diagnostics.Process.Start( "notepad.exe", @"C:\Documents and Settings\bob\Desktop\Doug.xml" ); } Thanks for your help!

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      What's the error? And why is your XmlDocument "global"? You realize that more than one person could call this method concurrently, don't you? Your current method will invariably break because someone may get someone else's data since the variable reference could change mid-execution (since a CPU slices time between threads and processes). Besides, your web application can't access a file on the client machine like that! That just isn't possible. In order to do that, you would have to either specify a path on the server or upload the document to the web server first. This doesn't have to be persistent, however. You could pass a stream that the web service would save to a file. Actually, though, a web server is probably not a good solution for your problem if all you're trying to do is upload a file. Simple HTTP can handle this easier than SOAP. You'd simply make a new HttpWebRequest, get the request stream, and pass the file. The handler on the server would get this stream and save it to a directory, passing back an HttpWebResponse that tells if it was successful or not. Be careful with this kind of solution, however, since the user your web application runs as (by default, this is ASPNET for ASP.NET and IUSR_YOURCOMPUTERNAME for IIS itself) will need write permissions. This means anyone could upload anything and could potentially upload - say - a .aspx file that deletes most of your hard drive! This is where you should try impersonation (even with the web service, which gets a little harder but isn't too bad) using the HttpWebRequest.Credentials property (and disabling anonymous access on the web server with something else enabled like Windows Integrated Authentication), or the WebClientProtocol.Credentials property, which your web service consumer class inherits.

      Microsoft MVP, Visual C# My Articles

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups