0

i have a simple xml file in a wcf service that i am trying to load using Xelement.Load("sample.xml") which is not reading the file. What's the right way of doing this?

The service is supposed to return an xml to an asp.net application.

TIA

SoftwareGeek
  • 15,234
  • 19
  • 61
  • 78
  • what error (if any) are you getting? is the problem reading the file on the server side?? Are you sure you're reading frmo the right location? Does your service has permission to read from that location?? or is the problem passing back that string to the caller - please clarify! – marc_s Mar 11 '10 at 16:53
  • @marc_s: the service in wcf throws 'FileNotFoundException'. The xml file is located in wcfservicelibrary1 project root & trying to load from file Service1.cs – SoftwareGeek Mar 11 '10 at 17:12
  • check your paths, and permissions. – Cheeso Mar 12 '10 at 12:23
  • @Cheeso - how do we pass the correct path to the load method? i couldn't even code for server.mappath, what am i missing? – SoftwareGeek Mar 12 '10 at 23:37
  • I don't know what you mean by that. maybe if you showed some code, we'd be able to offer some better insight. – Cheeso Mar 12 '10 at 23:57
  • @Cheeso - this code throws the error. XElement _x = XElement.Load("XMLFile1.xml"); i tried to do XElement.Load(Server.Mappath("XMLFile1.xml")); but this was not possible. – SoftwareGeek Mar 13 '10 at 00:11
  • Better to post the code in the question. Also - Server.MapPath is not found in a WCF service, as far as I know. – Cheeso Mar 13 '10 at 00:13

2 Answers2

0

You should try something like this then.

var appPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath; bodyFile = Path.Combine(appPath, @"<File Name Path");

This will work relative to your application's physical path.

Evan Anger
  • 712
  • 1
  • 5
  • 24
0

I got it to work by providing the ABSOLUTE path as the parameter to the XElement.Load() method, RELATIVE path would be better though.

SoftwareGeek
  • 15,234
  • 19
  • 61
  • 78