Hi guys,
I am stuck at one point while using XMLPORTS. I have created an XMLPORT and a Codeunit for importing the data from an xml file. When I run the Codeunit locally, the data gets imported and everything looks fine.
The problem is, when I try to run the same Codeunit using Web Service, the XMLPORT.IMPORT function fails and returns the exception "Import Unsuccessful". Any ideas resolving the same would be highly appretiated.
Awaiting on the responses. Thanks in advance.
Following is the code that I am using for Import.
SendOrderDetails() FileExists : Boolean
IF EXISTS('C:\inetpub\wwwroot\Import Files\OrderDetails.xml') THEN
BEGIN
IF TestFile.OPEN('C:\inetpub\wwwroot\Import Files\OrderDetails.xml') THEN
BEGIN
TestFile.CREATEINSTREAM(VarInStream);
IF XMLPORT.IMPORT(50007,VarInStream) THEN
FileExists := TRUE
ELSE
ERROR('Import Unsuccessful');
END ELSE
ERROR('Error Opening file');
TestFile.CLOSE;
END ELSE
FileExists := FALSE;
Dilip
Falling down is not a defeat..defeat is when you refuse to get up.
0
Comments
You can use the UPLOAD function to copy the file to a temp folder on the service tier and try to import it from there (store the path in a variable).
InsertIncident(VAR parXmlPort : XMLport XMLport50015)
parXmlPort.IMPORT();
Thanks for the response.
I guess, that should not be the problem based on below two assumptions.
1. The TESTFILE.OPEN function returns true in the same code, which means it is able to open the file from the path. It just fails when calling the IMPORT function of the XMLPort after the xml file has been read from the path and hence throws the exception "Import Unsuccess". If there is problem in finding the path, the exception should have been "Error Opening File" which is mentioned as error msg in the sample code.
2. Secondly, I am using the following code for export which works fine with the webservice call.
TestFile.CREATE('C:\inetpub\wwwroot\Export Files\LoginDetails.xml');
TestFile.CREATEOUTSTREAM(TestStream);
XMLPORT.EXPORT(50004,TestStream);
TestFile.CLOSE;
Thanks again.
Falling down is not a defeat..defeat is when you refuse to get up.
You could try the following code:
Since I am exposing the codeunit as a web service, hope I cannot use UPLOAD function as it promts for a dialog box for selecting the file.
Instead I have tried using the below code:
The above code works fine when run locally but I am really stuck why the web service call cannot run the varxml.import function and it throws the exception "Import Unsuccessful". Really stuck ](*,) ](*,)
Going mad :x
Falling down is not a defeat..defeat is when you refuse to get up.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
In that case, the web service throws the exception as shown in the attachment. I doesnt have any clue why is this happening when the same is working fine locally.
:-k :-k :-k :-k :-k
Falling down is not a defeat..defeat is when you refuse to get up.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
But the XMLPORT which I am using for IMPORT doesnt have any set of code. Any idea where the confirm or dialog possiblities would come while using IMPORT??
Falling down is not a defeat..defeat is when you refuse to get up.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Also for testing, I am trying to import only the primary key value of the table. And the table doesnt have any set of code in the OnIsert() and OnValidate() of the field which I am using in the XMLPORT.
Still the problem is same ](*,)
Falling down is not a defeat..defeat is when you refuse to get up.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
But...
I have gone into the next problem now with the same web service. The next tast is to print the imported data from a windows printer. For that...
1. I have created a very simple report with just one data item
2. one control in the body section of that.
3. No code on the report.
4. Layout is created.
When I try to run the report, the same works fine locally, but again problem is when run using web service.
The system throws an exception saying "Callback Functions are not allowed"
Any clue where the user interface is obstructing with the following two line of simple code. Awaiting on some ideas in breaking the same :-k :-k
Thanks all in advance.
Falling down is not a defeat..defeat is when you refuse to get up.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
http://www.mibuso.com/forum/viewtopic.php?f=32&t=46507&hilit=print+pdf
Please read last page carefully. I ended up writing a .net service that uses a FileSystemWatcher Class to watch a folder for incoming pdfs which had the printer name encoded in their filename to print the pdfs trough foxxit pdf reader (the external service is needed so you can run it under a domain user which you can assign printers to). I guess that's the best solution to do this!
Note: If you set up your NST to run under a domain account then you probably don't need the external service, you can do it with .net interop so foxxit reader would run under the context of a user that has printers assigned.
Also, as we are working on NAV 2009 SP1, kindly mention how the below function of your's should be changed as we dont have the dotnet datatype. Awaiting on your response deV.ch, Thank you in advance.
Falling down is not a defeat..defeat is when you refuse to get up.
To save the file you can use this code:
GetPrinterSelection():
GetFileName():
The GetFileName Function uses .net interop again, so you will need to rewrite it to get the same result. maybe File.CREATETEMPFILE or something like that to create a unique file name. The Printer Name is encoded since you can't use backslashes etc, in file names. I used .net interop here as well, but there is a Function UrlEncode in NAV Codeunit 801.
Thats all for the NAV Part.
Here is the a simplified version of my code in the service that prints the pdf files:
And The Code for the PrintPDFHelper.PrintPDF Method
Regrets if I am troubling you, I tried searching for creating a dotnet service but with no success. I have no knowledge on dotnet. Could you pls. mention the steps for the creating the dotnet service with the code u have mentioned as is below and how to use the same for NAV. I would be grateful to u.. Thanks in advance.
Falling down is not a defeat..defeat is when you refuse to get up.
I provided you my class Service1 which is equal to the class "WindowsService" in this tutorial. You can copy the code in the project you will create.
Since NAV is pushing in that direction i recommend you getting in touch with the whole .net world. but if you can't get it to work, i recommend you to conntact a .net developer to create this for you.
Unfortunatly right now i have no time to create a public version of my solution. Maybe i will do this in the near future. I see this could probably help some people, also i see that i should sum the whole topic up in a proper blog post. Since it involves lots of different parts, like permissions, domain users, windows services, pdf readers, etc...
Let me know if you managed to create the service, once you have this, its almost done.