SBX - Search With Button

SBX - Forum Post Title

Parse data from NAV to CRM through WCF

Microsoft Dynamics NAV Forum

Daniel Pereira asked a question on 17 Aug 2018 10:49 AM
My Badges

Question Status

Verified

Hi Everyone,

I have a requirement wherein I need to pass "real-time" data from NAV to CRM via an intermediate custom WCF service which will be used as an adapter between the two systems. For example, when I create a new item in NAV, the record should synchronously be passed to CRM as a product. The same follows for update and delete operations as well.

Since, I can't directly expose the entity as a web service in NAV, what other method should I use to export data to my WCF? Also, should my data be SOAP or REST based?

Awaiting a reply soon. Thank You!

Reply
Verified Answer

If I have understood the scenario, you have a WCF service that acts as a “middle tier” between NAV and CRM. If this is the scenario, an action that occurs in NAV (for example Item creation) must be passed to the WCF service and then from it to CRM. So:

1) NAV has to call a method of your WCF service

2) Your WCF service must expose a method to receive Item details and then call a CRM service for create the item in it.

To call a WCF service from NAV, you can use C/AL, you can create an extension by using AL and HTTPClient or you can create an addin with C# that triggers your WCF service.

This is the only scenario that guarantees real-time communication, so you don’t have to expose services from NAV. All the synch logic is in your WCF service.

Instead, if a “timer logic” can be acceptable (for example your WCF service checks NAV every N minutes/seconds for data to be transferred to CRM) you can expose the Item Card page as web service and use this as a SOAP ws. Your WCF service will call methods like a classic SOAP WS. You can also use REST APIs natively exposed by NAV 2018.

Reply
Daniel Pereira responded on 17 Aug 2018 6:48 PM
My Badges

Hi Stefano,

Yes you understood the scenario correctly. C/AL is the only option as I haven't worked on AL nor control add-in.

About passing data to the WCF method on create item event, I had apparently created an XMLPort in combination with a Codeunit to be exposed as a SOAP WS but not sure if it is the right approach. Would appreciate your input if i'm in the right direction.

Thank you!

Reply
Verified Answer

You cannot expose an XmlPort as a SOAP WS. A codeunit is the right way but for a real-time synch it’s your C/AL code that must call the WCF service every time an item is created or modified or deleted. To call your WCF service from C/AL you can use cu 1290, here an example:

community.dynamics.com/.../call-external-web-service-using-new-cu-1290

For many scenarios like this, writing a C# addin (DLL) that expose a method to NAV (for example a method SynchItem) and inside this method (inC# code) you call the WCF service is the easiest way to do.

In this case, in C/AL you can declare a DotNet variable using your addin and then simply call MyAddin.SynchItem passing the parameters you want. Then it’s the addin that has the logic to call the WCF service.

Reply
Daniel Pereira responded on 19 Aug 2018 7:44 AM
My Badges

Thanks for your suggestion and I shall try this approach.

Reply
Daniel Pereira responded on 20 Aug 2018 6:11 AM
My Badges

Hello,

I referred the link that you provided. Here is my code:

Url := 'www.dneonline.com/calculator.asmx';
reqText := '<soap:Envelope xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xsd="www.w3.org/.../XMLSchema" xmlns:soap="schemas.xmlsoap.org/.../envelope">'+
'<soap:Body>'+
'<Add xmlns="http://tempuri.org/">'+
'<intA>4</intA>'+
'<intB>2</intB>'+
'</Add>'+
'</soap:Body>' +
'</soap:Envelope>';

// save request text in instream

TempBlob."Primary Key" := 1;

TempBlob.Blob.CREATEOUTSTREAM(ReqBodyOutStream);

ReqBodyOutStream.WRITE(reqText);

TempBlob.Blob.CREATEINSTREAM(ReqBodyInStream);

// run the WebServReqMgt functions to send the request

WebServReqMgt.SetGlobals(ReqBodyInStream,Url,Username,Password);

WebServReqMgt.DisableHttpsCheck;

WebServReqMgt.RUN;

// get the response

WebServReqMgt.GetResponseContent(RespBodyInStream);

ResponseXmlDoc := ResponseXmlDoc.XmlDocument;

ResponseXmlDoc.Load(RespBodyInStream);

MESSAGE(ResponseXmlDoc.InnerXml);

I am receiving the following error:

Am i passing the reqText properly? Or where is the issue? It will be nice if you could help me out with this. 

Thank you.

Reply
Verified Answer

If I have understood the scenario, you have a WCF service that acts as a “middle tier” between NAV and CRM. If this is the scenario, an action that occurs in NAV (for example Item creation) must be passed to the WCF service and then from it to CRM. So:

1) NAV has to call a method of your WCF service

2) Your WCF service must expose a method to receive Item details and then call a CRM service for create the item in it.

To call a WCF service from NAV, you can use C/AL, you can create an extension by using AL and HTTPClient or you can create an addin with C# that triggers your WCF service.

This is the only scenario that guarantees real-time communication, so you don’t have to expose services from NAV. All the synch logic is in your WCF service.

Instead, if a “timer logic” can be acceptable (for example your WCF service checks NAV every N minutes/seconds for data to be transferred to CRM) you can expose the Item Card page as web service and use this as a SOAP ws. Your WCF service will call methods like a classic SOAP WS. You can also use REST APIs natively exposed by NAV 2018.

Reply
Verified Answer

You cannot expose an XmlPort as a SOAP WS. A codeunit is the right way but for a real-time synch it’s your C/AL code that must call the WCF service every time an item is created or modified or deleted. To call your WCF service from C/AL you can use cu 1290, here an example:

community.dynamics.com/.../call-external-web-service-using-new-cu-1290

For many scenarios like this, writing a C# addin (DLL) that expose a method to NAV (for example a method SynchItem) and inside this method (inC# code) you call the WCF service is the easiest way to do.

In this case, in C/AL you can declare a DotNet variable using your addin and then simply call MyAddin.SynchItem passing the parameters you want. Then it’s the addin that has the logic to call the WCF service.

Reply

SBX - Two Col Forum

SBX - Migrated JS