We are calling AX code from Enterprise Portal that uses WinApi::CopyFile method.
When we run EP from a browser window that is running on the same machine as Business Connector and IIS, the code works.If we run EP from a browser window running on a local machine,WinApi::CopyFilereturns
The solution is to use WinAPIServer instead of WinAPI.From Dynamics AX Writing Secure X++ Code white paper you will find following:
All methods on the WinAPI are restricted to run only on the client. A new class, WinAPIServer, has been created. This class has a limited subset of the WinAPI functionality. Each method call on the WinAPIServer class is authorized before it can call into Windows. It is important to use the right version of the class.Calls made through WinAPIServer will execute in the security context of the AOS. Typically, the authenticated user running the client will not have any privileges on the AOS. This can lead to potential security issues if the AOS performs arbitrary tasks on behalf of the client.
As method DocuActionArchive.add() is not run on server but on client you cannot use WinAPIServer. So solution here is to write method which will be run on server.If you want to store files from document management on Sharepoint then in "Document management parameters" you should use UNC patch to document library, please see following links for reference: Accessing SharePoint Document Library through UNC Path