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. } }
Comments
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.
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.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
That's what you mean, I didn't try form other application.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
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."
I'll hope that can help you:
1- SERVER 1: Export customer.
I think you have put something like this to send data.
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.
Bye
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..
Eric Wauters
MVP - Microsoft Dynamics NAV
My blog
i am not sure my post could help you or not, let see.