In one of the previous articles “Using Web Service Event – Export Connection” we explained the use of Web Service event for an export connection.
In the following section we will demonstrate the use of Web Service event in an import connection (Direction = Write), where in you can import data into Microsoft Dynamics NAV. When you import data into Microsoft Dynamics NAV, an external party makes a call to Microsoft Dynamics NAV Web Service. The Web Service is linked to the BIS Web Service Event codeunit which triggers the pipeline. Other pipeline activities handle the rest of the data import.
There are two commands for importing the data from the external party into NAV:
- Write Document: When you use this command, the data is exported to NAV and added to the Message Queue. The BIS Pipeline waits for the Job Queue to finalize the import. This is an asynchronous process.
- Write Document With Response: When you use this command, the data is exported to NAV and immediately processed through the complete pipeline in a synchronous process.
As pointed out in earlier article, there are few things to note before we proceed with an example:
- The Web Service Event uses standard Microsoft Dynamics NAV web service functionality. Please refer to the standard online help to learn about Working with Web Services.
- You also need your own client to invoke the web service. This is not in the scope of BIS. However, for testing purpose, you can download and use WCF Storm. It is a free and open source tool for testing web services.
Example:
Setup the Connection:
In this example we will use an existing template to import sales order TI_CS_SALESORDER.IN (available in the software package Or download it here) and modify it to use Web Service event instead of File Reader endpoint.
- Click Departments/Business Integration Solutions/Connectivity Studio/Design/Connections
- Import the connection TI_CS_SALESORDER.IN from the sample templates.
- Remove the FILEREADER endpoint form the element list and add WEBSERVICEEVENT. Also make the necessary changes in the pipeline.
- Edit the Web Service Event and fill in the following fields:
Check the Web Services:
- Click Departments/Administration/IT Administration/General/Web Services.
- Click Edit List.
- Select the web service created in previous step (SO_IMP_WS in this case).
- Select the Published checkbox. This will also automatically generate a SOAP URL.
This SOAP URL is ready to be used by your client. Copy the URL and open it in a browser to check the result.
Invoking the Web Service Via Client:
- For testing purpose, run WCF Storm.
- Click Add and add the SOAP URL.
- From the software package:
- Open the sample file SalesOrderDemo.xml in notepad.
- Remove the Word Wrap check (Format, Word Wrap) from the notepad and put everything in one line.
- Copy the content.
- On the WCF Storm window, paste the content in the value of documentString property.
- Click Send.
- Go the the TI_CS_SALESORDER.IN connection and check the result in History.
The sales order have been imported into Microsoft Dynamics NAV.