Navisionguider.dk
Kursusmateriale: Lager 1
Indholdsfortegnelse til lærebogen "Lager 1 til Microsoft Business Solutions Navision 4.0".

How to use XMLports to connect to web services


How to use XMLports to connect to web services Navision 4.00 and XML namespaces

This article describes how to handle namespaces in XMLports in Navision 4.00.
 

Oversigt

A web service is a programmatic interface for application to application communication through the internet. The communication protocol is based on XML documents. An XML document usually contains namespaces to qualify its element and attribute names. Both applications must support namespaces to communicate.

 

XMLports in Navision can be used to generate XML documents and communicate with web services. But they do not support namespaces in version 4.00. A simple method is described in this article to get around this limitation.

 

Tekniske oplysninger

To communicate with a web service, XMLports in Navision need to send and receive XML documents containing namespaces.

1. Sending XML documents

In the XMLport, the TagType “Attribute” can be used to define XML namespaces.

For example, add the following tag in an XMLport:

TagName: xmlns
TagType: Attribute
SourceType: Text
DataSource: xmlns1

Add the following C/AL code line in the OnPreXMLport() trigger of the XMLport:

xmlns1 := 'http://schemas.xmlsoap.org/soap/envelope/';

2. Receiving XML documents

Before processing an XML document with an XMLport, an XML stylesheet can be applied to remove namespaces. An XML stylesheet contains a language for transforming XML documents into other XML documents.

For example, the following procedure can be used in Navision:

RemoveNamespace(
    XMLSourceDocument : Automation "'Microsoft XML, v4.0'.DOMDocument40";
VAR XMLDestinationDocument : Automation "'Microsoft XML, v4.0'.DOMDocument40")

TempTable."BLOB Field".CREATEOUTSTREAM(OutStreamStylesheet);
TempTable."BLOB Field".CREATEINSTREAM(InStreamStylesheet);
OutStreamStylesheet.WRITETEXT('<?xml version="1.0" encoding="UTF-8"?>');
OutStreamStylesheet.WRITETEXT('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">');
OutStreamStylesheet.WRITETEXT('<xsl:output method="xml" encoding="UTF-8" />');
OutStreamStylesheet.WRITETEXT('<xsl:template match="/">');
OutStreamStylesheet.WRITETEXT('<xsl:copy>');
OutStreamStylesheet.WRITETEXT('<xsl:apply-templates />');
OutStreamStylesheet.WRITETEXT('</xsl:copy>');
OutStreamStylesheet.WRITETEXT('</xsl:template>');
OutStreamStylesheet.WRITETEXT('<xsl:template match="*">');
OutStreamStylesheet.WRITETEXT('<xsl:element name="{local-name()}">');
OutStreamStylesheet.WRITETEXT('<xsl:apply-templates select="@* | node()" />');
OutStreamStylesheet.WRITETEXT('</xsl:element>');
OutStreamStylesheet.WRITETEXT('</xsl:template>');
OutStreamStylesheet.WRITETEXT('<xsl:template match="@*">');
OutStreamStylesheet.WRITETEXT('<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>');
OutStreamStylesheet.WRITETEXT('</xsl:template>');
OutStreamStylesheet.WRITETEXT('<xsl:template match="text() | processing-instruction() | comment()">');
OutStreamStylesheet.WRITETEXT('<xsl:copy />');
OutStreamStylesheet.WRITETEXT('</xsl:template>');
OutStreamStylesheet.WRITETEXT('</xsl:stylesheet>');
IF ISCLEAR(XMLStyleSheet) THEN
  CREATE(XMLStyleSheet);
XMLStyleSheet.load(InStreamStylesheet);
IF ISCLEAR(XMLDestinationDocument) THEN
  CREATE(XMLDestinationDocument);
XMLSourceDocument.transformNodeToObject(XMLStyleSheet,XMLDestinationDocument);

Add the following C/AL Locals in the procedure:

TempTable: Record
OutStreamStylesheet: OutStream 
InStreamStylesheet: InStream 
XMLStyleSheet: Automation "'Microsoft XML, v4.0'.DOMDocument40"

 

Supportoplysninger

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and the tools that are used to create and debug procedures.

 

Til toppen af siden

Kommentar

Du skal være logget ind før du kan se eller skrive kommentarer til de forskellige indlæg. Klik her for at logge ind, eller oprette en bruger.
Søg i teksten

Artikel type
- Vejledning

Skrevet af
- Mette Vestergaard

Funktioner
· Anbefal til ven
· Printervenlig
· Kommenter / Bedøm
· Vis fuldskærm

Nøgleord
- 4.0
- Navision 4.0
- XML Ports