I want to use xmlport to import data from web service, So I create a xmlport file , then create a codeunit to call this xmlport .
UpdateVehicle(VAR BaseVehicle : XMLport "Import Vehicle";VAR ErrMsg : Text) : Boolean
IF NOT (BaseVehicle.IMPORT) THEN BEGIN //WS1.78 TEST
ErrMsg := 'failed.';
EXIT(FALSE);
END;
BaseVehicle is a xmlport based on Temp table,
i want to check the imported data, how can i export the transfered-in data ?
I mean , if xmlport.import is false, how can i save the data to txt for debuging?
I’ve used a similar code to save a log with XML received (is not exactly XML received, but was what I was looking for), but not in case of error in XMLport.
UpdateVehicle(VAR BaseVehicle : XMLport "Import Vehicle";VAR ErrMsg : Text) : Boolean
IF NOT (BaseVehicle.IMPORT) THEN BEGIN //WS1.78 TEST
TempBlob.Blob.CREATEOUTSTREAM(OutStrm); // TempBlob is a record Var of TempBlob table, OutStrm is a OutStream VAR
BaseVehicle.SETDESTINATION(OutStrm);
BaseVehicle.EXPORT;
// Do something here with TempBlob.Blob, you can save to a file or in an other BLOB field
ErrMsg := 'failed.';
EXIT(FALSE);
END;
I have to say that I’m not shure if this will work, if IMPORT gives an error, I think it will not contain any data.
What did you do before this updateVehicle function?
I assume that you already have already called your web response and streamed it into NAV? And that’s the reason you have BaseVehicle as a VAR var?
If your import fails, then you need to stream that into a Blob field? Then you can use the FileManagement codeunit to save the file.
UpdateVehicle(VAR BaseVehicle : XMLport "Import Vehicle";BlobField: Blob; VAR ErrMsg : Text) : Boolean
IF NOT BaseVehicle.IMPORT THEN BEGIN
TempBlob.INIT;
TempBlob.Blob := BlobField;
FileName := 'WhatEverYouWant.txt';
FileManagement.BLOBExport(TempBlob,FileName,TRUE);
END;
Personally I have never used XMLPorts for web services. I know that you could do that, but I have always preferred to have full control, when dealing with web services. Instead I use the build-in/DotNet XMLDom functionality. This way it’s possible to give much better feedback to the user towards what went wrong.
yup, you are right, But if it is ok for dotnet dll to received the data from outside and then insert into navision? in fact, I have another dll control to send the data from navision.
I supose that Gary has published a web service in NAV that some one else will use to send data… UpdateVehicle is the web service function to receive information that will be imported through BaseVehicle XMLport.
I’ve used this method to publish a web service for both, receive or send data… in case I have to connect to external web service, I always use XMLDom, as you mention.
BTW, Have you got suche problem before ? i use xmlport.import more than 4000 reocrds (i used the temp table in xmlport), I got a null return value from the method of web service.
Perhaps it’s a timeout problem. By default, when you connect to a web service, and do some action, there is a period of time until system return a timeout if no response is received.
if you leave the IMPORT alone and no check the returned value, what does it happen? Does It return some error when you call the web service function?
hi Ponç J. , thanks for your reply, yup, I have tested, when I change the SOAP SERVICE MAX MESSAGE SIZE from 1024 to 4048, the records transfer-limites changed to be 1500 to 6200, So i felt, may be this problem leads to the error.
IF NOT (BaseVehicle.IMPORT) THEN BEGIN //WS1.78 TEST
TempBlob.Blob.CREATEOUTSTREAM(OutStrm); // TempBlob is a record Var of TempBlob table, OutStrm is a OutStream VAR
BaseVehicle.SETDESTINATION(OutStrm);
BaseVehicle.EXPORT;
if this is an error ? why can not got the error information be saving to the text files? if there is an error in my code? i have never used tempblog before, thanks in advance.
Hi, I am just testing how to get the error message ,if BaseVehicle.import fails. I removed the if -condition, Just let BaseVehicle.import be along, Now I got a error exception " 未经处理的异常: System.Web.Services.Protocols.SoapException: Imported XML canno
t validate with the schema: The element ‘VehicleLine’ in namespace ‘urn:microsof
t-dynamics-nav/xmlports/x50043’ has incomplete content. List of possible element
s expected: ‘LastChangeTime’ in namespace ‘urn:microsoft-dynamics-nav/xmlports/x
50043’. " from navision, I know this error, But How can i save it to a error text file ? thanks in advance.
It’s what I said in my first response, when XMLport gives an error, the system will rollback all modifications (and this include all inserts in temp table). The only way to do what you want is creating a file var and in XMLPort VehicleLien OnBeforeInsertRecord, and manually save the information you want in the file. If you don’t want that file remains open when an error happens, you will need to open and close everytime.