Problem reading xml file in WCF service
WCF service has one method (say TestMethod) in which I am trying to create a file stream like this:
System.IO.FileStream fs = new System.IO.FileStream(@"D:\Test.xml", System.IO.FileMode.Open);
My client and service are on the same solution.
When the Client makes a TestMethod call (Exposed in Web Service), it will throw this error:
Access to the D: \ DXDirectoryAuth.xml path is dispatched.
Please, help!!
You tried:
System.IO.FileStream fs = new System.IO.FileStream(@"D:\Test.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read);
The default constructor FileStream () requests read / write access.
Well, if you put the file in a directory or subdirectory of your WCF service, you should be able to access the file without any permissions issues.
The question is, how are you trying to access the file?
You should probably get the current directory of the service, then add the relative location of the file to the current directory, and then try to open the file like this:
var appPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
bodyFile = Path.Combine(appPath, @"templates\email.txt");
var body = File.OpenText(bodyFile).ReadToEnd();
NTN
Ollie
Safety
The reason you are trying to access a file location outside of the directory that hosts your WCF service ...
You will either have to provide an account that WCF runs under permissions in this directory, or move the file to the directory \ subdirectory where you host the WCF service.
Ollie