mibuso.com

Microsoft Business Solutions online community
It is currently Sat May 18, 2013 11:00 am

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: XMLPORT.IMPORT fails while using with webservice
PostPosted: Tue Feb 28, 2012 8:12 am 
Offline

Joined: Wed Oct 04, 2006 12:46 pm
Posts: 120
Location: India
Country: India (in)
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.


Top
 Profile  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Tue Feb 28, 2012 10:07 am 
Offline

Joined: Mon Sep 26, 2011 9:40 am
Posts: 38
Location: Nijmegen
Country: Netherlands (nl)
A XML-Port look for 'C:\inetpub\wwwroot\Import Files\OrderDetails.xml' at the server where the service tier is running. So when you try to run this code it won't find the path because it is not there.

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).


Top
 Profile E-mail  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Tue Feb 28, 2012 10:32 am 
Offline

Joined: Sun Feb 26, 2012 7:09 pm
Posts: 10
Country: Czech Republic (cz)
I recommend do not use XML file stored on a disk (if it is possible). Be sure a function in the published codeunit can have parameter - type XMLport. In this case you can use this simple code in codeunit (InsertIncident is name of published method):
InsertIncident(VAR parXmlPort : XMLport XMLport50015)
parXmlPort.IMPORT();


Top
 Profile E-mail  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Tue Feb 28, 2012 10:41 am 
Offline

Joined: Wed Oct 04, 2006 12:46 pm
Posts: 120
Location: India
Country: India (in)
Hi Ploeg,

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.

_________________
Dilip
Falling down is not a defeat..defeat is when you refuse to get up.


Top
 Profile  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Tue Feb 28, 2012 11:03 am 
Offline

Joined: Mon Sep 26, 2011 9:40 am
Posts: 38
Location: Nijmegen
Country: Netherlands (nl)
It is indeed the IMPORT function that is the trouble. IMPORT and EXPORT are two completely different things.
You could try the following code:


Code: Select all
LOCAL VARS:
XMLFile -> File      
XMLStream -> InStream      
lPath -> Text (500)
lCduCommonDialogManagement -> Codeunit (Common Dialog Management)   
ConfPersMgt -> Codeunit (Conf./Personalization Mgt.)   
TempFile -> File      
Filename -> File   

TEXT CONSTANT:
LTXT_Filter -> XML files (*.xml)|*.xml|All files (*.*)|*.*   

IF ISSERVICETIER THEN
BEGIN
  TempFile.CREATETEMPFILE;
  lPath := TempFile.NAME + '.xml';
  TempFile.CLOSE;
  IF UPLOAD('Import XML', '',LTXT_Filter,'',lPath) THEN BEGIN
    XMLFile.OPEN(lPath);
    XMLFile.CREATEINSTREAM(XMLStream);
    XMLPORT.IMPORT([YOUR IMPORT], XMLStream);
    XMLFile.CLOSE;
  END;
END ELSE
BEGIN
  lPath := lCduCommonDialogManagement.OpenFile(
    'Select a Import file', '', 4, LTXT_Filter, 0);

  IF lPath <> '' THEN BEGIN
    XMLFile.OPEN(lPath);
    XMLFile.CREATEINSTREAM(XMLStream);
    XMLPORT.IMPORT([YOUR IMPORT], XMLStream);
    XMLFile.CLOSE;
  END;
END;


Top
 Profile E-mail  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Tue Feb 28, 2012 2:34 pm 
Offline

Joined: Wed Oct 04, 2006 12:46 pm
Posts: 120
Location: India
Country: India (in)
Hi Ploeg,

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:
Code: Select all
PushOrderDetails(VAR VarBigTxt : BigText) fileImport : Boolean
lrecTempBlob.Blob.CREATEOUTSTREAM(OutStr);
VarBigTxt.WRITE(OutStr);
lrecTempBlob.Blob.CREATEINSTREAM(InStr);
VarXML.SETSOURCE(InStr);
IF VarXML.IMPORT THEN
  fileImport := TRUE
ELSE
  ERROR('Import Unsuccessful');


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

_________________
Dilip
Falling down is not a defeat..defeat is when you refuse to get up.


Top
 Profile  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Tue Feb 28, 2012 3:28 pm 
Offline
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Thu Oct 16, 2003 8:50 am
Posts: 12265
Location: Brno
Country: Czech Republic (cz)
Try to call the import out of IF-Then to let NAV throw the original runtime error.

_________________
Kamil Sacek
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.


Top
 Profile E-mail WWW  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Wed Feb 29, 2012 7:36 am 
Offline

Joined: Wed Oct 04, 2006 12:46 pm
Posts: 120
Location: India
Country: India (in)
Hi Kamil,

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


Attachments:
WS Exception.png
WS Exception.png [ 39.17 KiB | Viewed 1098 times ]

_________________
Dilip
Falling down is not a defeat..defeat is when you refuse to get up.
Top
 Profile  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Wed Feb 29, 2012 7:41 am 
Offline
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Thu Oct 16, 2003 8:50 am
Posts: 12265
Location: Brno
Country: Czech Republic (cz)
THis exception means that you have confirm or dialog used in the code, but it means definitely, that the code is called at all... ;-)

_________________
Kamil Sacek
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.


Top
 Profile E-mail WWW  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Wed Feb 29, 2012 8:11 am 
Offline

Joined: Wed Oct 04, 2006 12:46 pm
Posts: 120
Location: India
Country: India (in)
Thanks Kamil for the reply.

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??

_________________
Dilip
Falling down is not a defeat..defeat is when you refuse to get up.


Top
 Profile  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Wed Feb 29, 2012 8:46 am 
Offline
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Thu Oct 16, 2003 8:50 am
Posts: 12265
Location: Brno
Country: Czech Republic (cz)
May be some OnValdiate or OnInsert is called in some table? How is the XMLPort called? It is as parameter of the function? Or through local variable?

_________________
Kamil Sacek
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.


Top
 Profile E-mail WWW  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Wed Feb 29, 2012 9:00 am 
Offline

Joined: Wed Oct 04, 2006 12:46 pm
Posts: 120
Location: India
Country: India (in)
Is called through local variable.

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 ](*,)

_________________
Dilip
Falling down is not a defeat..defeat is when you refuse to get up.


Top
 Profile  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Wed Feb 29, 2012 9:12 am 
Offline

Joined: Mon Sep 08, 2008 10:25 am
Posts: 484
Location: Switzerland
Country: Switzerland (ch)
Run the code from classic client or rtc client and see what the callback is (a confirm, a form/page, etc). then search for that.

_________________
My Blog


Top
 Profile  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Wed Feb 29, 2012 9:35 am 
Offline
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Thu Oct 16, 2003 8:50 am
Posts: 12265
Location: Brno
Country: Czech Republic (cz)
May be the XMLPort is asking for the file name? :-)

_________________
Kamil Sacek
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.


Top
 Profile E-mail WWW  
 
 Post subject: Re: XMLPORT.IMPORT fails while using with webservice
PostPosted: Wed Feb 29, 2012 2:04 pm 
Offline

Joined: Sun Feb 26, 2012 7:09 pm
Posts: 10
Country: Czech Republic (cz)
I solved the same error several moths ago. Unfortunately I can't remember what reason was that. I'm not sure but I have feeling that temporary table (Temporary property) and something around this was the cause.


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: