Problem with XMLport and webservice between 2 NAV databases
fzarateo
Member Posts: 10
Hi all, this is my second chance to solve this issue. ](*,)
My scenario is that I need to send data between 2 nav databases using webservices and xmlports.
I was using http://mibuso.com/blogs/ara3n/2009/01/2 ... companies/
XmlPort has the properties as image.
When run the codeunit all seems that works but the result is no data are sended to destiny.
I'm not sure about the use of xmlhttp and xmldoc with webservice in navision.
My scenario is that I need to send data between 2 nav databases using webservices and xmlports.
I was using http://mibuso.com/blogs/ara3n/2009/01/2 ... companies/
OBJECT Codeunit 50109 SyncroMgtBuso
{
OBJECT-PROPERTIES
{
Date=10/10/13;
Time=13:42:52;
Modified=Yes;
Version List=SGO-13-006,SGO-13-008;
}
PROPERTIES
{
OnRun=BEGIN
END;
}
CODE
{
PROCEDURE ImportCustomer@1000000003(VAR xmlImporClientes@1000000000 : XMLport 50001);
BEGIN
xmlImporClientes.IMPORT;
END;
BEGIN
END.
}
}
OBJECT Codeunit 50110 WS comunicate BUSO
{
OBJECT-PROPERTIES
{
Date=10/10/13;
Time=13:42:12;
Modified=Yes;
Version List=SGO-13-006,SGO-13-008;
}
PROPERTIES
{
OnRun=BEGIN
CustomerExport;
END;
}
CODE
{
VAR
nodeList@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNodeList";
node@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
i@1000000002 : Integer;
systemServiceURL@1000000003 : Text[1024];
customerPageURL@1000000004 : Text[1024];
SoapEnvelopeNS@1000000005 : Text[1024];
SystemServiceNS@1000000006 : Text[1024];
CustomerServiceNS@1000000007 : Text[1024];
baseURL@1000000008 : Text[1024];
cur@1000000009 : Text[1024];
rec_sales_setup@1000000010 : Record 311;
SGCustomerExport@1000000011 : Text[1024];
SGContactExport@1000000012 : Text[1024];
pageURL@1000000013 : Text[1024];
tempblob@1000000014 : TEMPORARY Record 99008535;
PROCEDURE InvokeNavWSXMLPort@1000000009(URL@1000000000 : Text[250];method@1000000001 : Text[20];nameSpace@1000000002 : Text[80];returnTAG@1000000003 : Text[20];xmldoc@1000000004 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";VAR nodelist@1000000005 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF82-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNodeList") result : Boolean;
VAR
xmlhttp@1000000006 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A0A-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.XMLHTTP60";
soapEnvelope@1000000008 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMElement";
soapBody@1000000009 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMElement";
soapMethod@1000000010 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMElement";
node@1000000011 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
parametersXmlDoc@1000000012 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";
BEGIN
result := FALSE;
CREATE(xmlhttp, TRUE, TRUE);
xmlhttp.open('POST', URL, 0, rec_sales_setup."Usuario WOK", rec_sales_setup."Pass WOK");
xmlhttp.setRequestHeader('Content-type', 'text/xml; charset=utf-8');
xmlhttp.setRequestHeader('SOAPAction', method);
xmlhttp.send(xmldoc);
// If status is OK - Get Result XML
IF xmlhttp.status=200 THEN
BEGIN
xmldoc := xmlhttp.responseXML;
xmldoc.setProperty('SelectionLanguage','XPath');
xmldoc.setProperty('SelectionNamespaces','xmlns:tns="'+nameSpace+'"');
nodelist := xmldoc.selectNodes('//tns:'+returnTAG);
result := TRUE;
END;
END;
PROCEDURE EncodeUriComponent@1000000004(uri@1000000000 : Text[80]) encodedUri : Text[240];
VAR
HexDigits@1000000001 : Text[30];
b@1000000002 : Integer;
BEGIN
// No URI Encoding in NAV - we do it ourself...
HexDigits := '0123456789ABCDEF';
encodedUri := '';
FOR i:=1 TO STRLEN(uri) DO
BEGIN
b := uri[i];
encodedUri := encodedUri + '% ';
encodedUri[STRLEN(encodedUri)-1] := HexDigits[(b DIV 16)+1];
encodedUri[STRLEN(encodedUri)] := HexDigits[(b MOD 16)+1];
END;
END;
PROCEDURE CustomerExport@1000000006() result : Boolean;
VAR
XMLCustomer@1000000002 : XMLport 50001;
xmldoc@1000000003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A05-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.DOMDocument60";
out_xml@1000000004 : OutStream;
rec_customer@1000000005 : Record 18;
in_xml@1000000000 : InStream;
BEGIN
IF baseURL = '' THEN
DefaultValues;
cur := 'SISTEMAS GENOMICOS MEXICO S.L.';
//pageURL := baseURL + EncodeUriComponent(cur) + '/Codeunit/GestIntercompany';
pageURL := baseURL + cur + '/Codeunit/ImportIntercompany';
rec_customer.RESET;
rec_customer.SETFILTER("Last Date Modified",'%1..',CALCDATE('-1D',TODAY));
IF NOT rec_customer.FINDSET THEN
EXIT(FALSE);
CLEAR(tempblob.Blob);
tempblob.Blob.CREATEOUTSTREAM(out_xml);
CLEAR(XMLCustomer);
XMLCustomer.SETTABLEVIEW(rec_customer);
XMLCustomer.SETDESTINATION(out_xml);
XMLCustomer.EXPORT;
//XMLPORT.EXPORT(50001, out_xml, rec_customer);
tempblob.Blob.CREATEINSTREAM(in_xml);
tempblob.Blob.EXPORT('e:\temp.xml');
CREATE(xmldoc,TRUE,TRUE);
xmldoc.load(in_xml);
result := InvokeNavWSXMLPort(pageURL, 'Importcustomers', SGCustomerExport, 'Customer', xmldoc, nodeList);
MESSAGE(FORMAT(result));
END;
PROCEDURE DefaultValues@1000000008();
BEGIN
rec_sales_setup.GET;
baseURL := rec_sales_setup."URL WebService";
systemServiceURL := baseURL + 'SystemService';
SGCustomerExport := 'urn:microsoft-dynamics-nav/xmlports/x50001';
END;
BEGIN
END.
}
}
XmlPort has the properties as image.
When run the codeunit all seems that works but the result is no data are sended to destiny.
I'm not sure about the use of xmlhttp and xmldoc with webservice in navision.
0
Comments
-
Hi
My suggestion to you would be that make the application short and simple by following the steps-
creating an xmlport with a customer sourcetable(temp).
-
create a codeunit and add functions CreateCust, SaveCust and ReadCust based on your req.
-
CreateCust would use xmlport as parameter. and call the xmlport.import in it.
-
ReadCust would use xmlport as var parameter and apply some filters in the code which you want to apply on the customer record, populate the source table of xmlport.
no need to write xmlport.export the WS will automatically handle it.
-
Publish the Codeunit (call it as CustomerWS) as WS by creating a record in webserivce page name it and then publish it)
-
In your VS Application you have to create a service reference of your WS and then based on the architecture of your xmlport you can call the diff. nodes and diff. functions of your webservice.
-
Remember to user Encoding as UTF-8, Format/Evaluate property as XML format in xmlport.
You have to handle the insertion or modification of records at the time of Import which you can do in xmlport.
For any other help you can always contact me.0 -
Hi prakaash786,
thanks for your reply but your solution is not that I need.
I need to send data from MasterDataBase in Navision to SlaveDataBase in Navision, too.
That's the reason that I export xmlport with customers and try to send it to webservice.0 -
have you tried to consume the xml port from webservice?0
-
I can access by webclient and show all fields that I want to export/import.
That's what you mean, I didn't try form other application.0 -
Sorry what I mean is have you tried to consume the NAV service from Visual Studio.0
-
fzarateo wrote:Hi prakaash786,
thanks for your reply but your solution is not that I need.
I need to send data from MasterDataBase in Navision to SlaveDataBase in Navision, too.
That's the reason that I export xmlport with customers and try to send it to webservice.
Hi fzarateo,
I also meant the same that from one database you need to send data to another and for that I was saying that you have to make a functionality that it will initiate a request( from slave database - Say get customers from Master), you have to code something in VS app (refernce that dll in your nav code) and then the request will go to VS Application(with WS path of Master) and pass its request from there to Master Database using WS and then bring the data in VS and pass it to the WS.navfunction as an argument using which is calling the xmlport.import and your data will be back to NAV.
and if you are working on your own solution then consider Rashed's query "Sorry what I mean is have you tried to consume the NAV service from Visual Studio."0 -
It's also a conicidence that guys who have joined this community in december are only responding
0 -
Hi
I'll hope that can help you:
1- SERVER 1: Export customer.
I think you have put something like this to send data.[b]ExportCustomer()[/b] CLEAR(TempBLOB); TempBLOB.Blob.CREATEOUTSTREAM(WriteStream); MyXmlPort.SETDESTINATION(WriteStream); MyXmlPort.EXPORT; TempBLOB.CALCFIELDS(Blob); TempBLOB.Blob.CREATEINSTREAM(ReadStream); locautXmlDoc.load(ReadStream); CLEAR(locautXmlHttp); CREATE(locautXmlHttp); locautXmlHttp.open('POST','Your WS',0); locautXmlHttp.setRequestHeader('Content-type','application/soap+xml; charset=utf-8'); locautXmlHttp.setRequestHeader('SOAPAction','Your WS/ImportCustomer'); locautXmlHttp.send(locautXmlDoc);
2- SERVER 2: Import Date.
I'll change he input parameter to a BIGTEXT.
Then, you can manage this bigtext and load the information in the XMLport.[b]ImportCustomer(ImportData : BigText)[/b]TempBlob.INIT; TempBlob.Blob.CREATEOUTSTREAM(WriteStream); ImportData.WRITE(WriteStream); TempBlob.CALCFIELDS(Blob); TempBlob.Blob.CREATEINSTREAM(ReadStream); MyXmlPort.SETSOURCE(ReadStream) MyXmlPort.IMPORT
Bye0 -
Hey Fernando,
I'm not sure I understand exactly what you try to do .. .
But I see that you're trying to do all with SOAP-calls. I must admit, that's also my favorite way to go. We usually avoid using dll's for using web services .. which would make it more complicated on the infrastructure/installation/maintenance side.
I also see that you're trying to go for the Codeunit/XMLPort way. Now, that's a combination that I haven't tried out (Soap with Codeunit-webservice), except from generation a PDF .. not for updating data..
Why aren't you using a page-webservice in stead? If I'm not mistaken, there are loads of examples online. Just to name a few:
- http://blogs.msdn.com/b/freddyk/archive ... 9-sp1.aspx
- http://vjeko.com/blog/web-services-blac ... g-pure-cal
If you set up 2 webservices, one for your master, one for your slave .. you should be good to go, no?
Just my two cents..0 -
http://www.mibuso.com/forum/viewtopic.php?f=32&t=57390
i am not sure my post could help you or not, let see.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 323 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

