The server-side impersonated (RunAs) session tried to invoke a method that
is available for client-side processing only.
how can i access files on client when my code is running on the server.
Class WinAPI has property RunOn set to "Client". Thus it will be executed on
client.
Class WinAPIServer is dedicated for server needs.
I suspect origin of the problem is in the wrong path to file. Are you using
something like: winapi::fileExists(@"c:\folder\filename.ext)?
Mykola
One thing to consider is that if the file was specified by the user on the
client, then one likely cannot attempt to load the file from the server,
unless it's 100% certain that it's a network path. Even then, the server may
not have access to that network location.
The safest solution to this problem--if possible--is to load the file before
this process begins and store the requisite data into a list or some other
structure that is serializable. This serialized data could then be used by
the server at execution time.
Also, if this is not a headless (client-less) process running through the
new batch framework (RunBaseBatch), one could create a "static client" method
that loads the file on the client and returns the results through a
serialized list.
What version of Ax are you using and what's your precise scenario? It looks
like you're injecting your code into something being executed through
RunBaseBatch.
To clarify your scenario, by "access a file", you mean "checking if the file
exists before you write to it?"
Thanks!
--
This posting is provided "AS IS" with no warranties, and confers no rights.
One side effect of the (new) headless (clientless) batch framework is that
you *cannot* run client-dependent code in that batch process--thereby
requiring that you either remove client-dependencies or branch around them
when running in batch.
In this case, I believe you've taken the correct initial approach in using
winapiserver instead of winapiclient (although I suspect the problem may be
deeper than this).
I'll ping the appropriate people about winapiserver and find out if that's a
legal call from a batched process.
In the mean time, I have a hunch that the AOS is running as a user that does
not have access to the file location specified.
To check this, do the following:
1) Locate the AOS that the batch is running on (make sure you account for
all the AOS's if running in a multi-AOS environment).
2) On the AOS machine, determine what user the AOS process is running under
by viewing the service in the Services explorer and right clicking on it,
selecting "properties" and then going to the "Log on" tab. If you're in a dev
environment, this will probably be the "NETWORK SERVICE" account.
3) On the AOS machine, browse out to the file path and verify that the
account you determined in step (2) has permissions to read and write there.
If not, you've determined your error.
If this does turn out to be the problem, I have a couple of conclusions that
I'll share with you. :)
I have the same problem: i can't create a file with a batch class under 2009.
My method is a server static, i use a fileiopermission.asset before a new on
asciiio class.
Is possible that there are permission problems on the service user?
How work runImpersonated?
thanks
runsImpersonated is meant to impersonate an AX user. This allows batch jobs
to run under the account of the user that created them, rather than an
ellevated system account, e.g.
I recommend that you identify which user the AOS service is running under
and verify that the identified user has access to the file(s) in question.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
What DID work was discovered by a co-worker of mine was using the system
class FileIOPermission. Here's a code snippet:
#File
TextIO io;
FileIOPermission permission;
;
//Explicitly ask for file permission to the
//location we want to write the file to
permission = new FileIOPermission(filename, #IO_Write);
permission.assert();
io = new TextIO(filename, #IO_Write);
if (!io)
{
throw error(strfmt("Error writing file %1",filename));
}
...
<do whatever writing you need to do here>
...
// Release permission
CodeAccessPermission::revertAssert();
This allows the process to work whether it's executing on the server or the
client. Hope this helps.
--
Best Regards,
Justin