From Team Developer SqlWindows Wiki
Revision as of 15:13, 18 July 2018 by DaveRabelink (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Webservices & XML


Pointer2.png Consume SOAP Webservices & REST/JSON using Microsoft XMLHTTP Pointer.png

This article describes how to consume (SOAP/XML) web-services and REST/JSON services using Microsoft XMLHTTP library.
Though Team Developer gained support to consume these services over the years, there are several drawbacks using native TD functionality.

Obviously, when you are still using an older TD version there is no support at all out-of-the-box.
But even on the latest TD versions, these issues might force you not to use the native TD features:

  • Native TD implementations could be buggy which forces you to find other solutions
  • Not all needed functionality is offered by TD, specially when you need more advanced features

Well, an alternative is using the native Windows support for consuming SOAP web-services and REST/JSON services.
Every Windows version has this by default build in and TD can easily use the Microsoft libraries.
Using Windows components gives you more access to advanced features and does not need 3rd party installations or custom setups.
The same code will work in all TD versions.

The most obvious way is to use the Microsoft XML library, which has a ActiveX/COM interface.
Using that library is fairly simple.

The first step is to create the TD ActiveX library using the ActiveX Wizard.
In Team Developer IDE, start the ActiveX Explorer from the Tools menu.

ActiveX Explorer1.png

Locate the Type Library "Microsoft XML, 6.0" and generate the library (apl).
Include the generated library into your project.

ActiveX Explorer2.png

The Microsoft XML library contains two COM Proxy Classes which are used to implement consuming services:

  • MSXML2_ServerXMLHTTP60

Which one to use depends on the features needed. This article will not discuss the differences between these classes.
More info can be found using Google search "XMLHTTP vs ServerXMLHTTP" which will give you many results.

Broadly speaking, the overall steps to take to consume services is this:

  • Create the COM proxy class object using the Create() function
  • Open a connection to the service URL using the needed HTTP action (PUT, POST, GET etc) using the open(..) function
  • Place needed request data into the request body
  • Set needed options/attributes for the header of the request
  • Use the send(..) function to actually call the service

Depending on the response of the service you need to

  • Check the HTTP status to determine the service response (OK, Error etc)
  • Get the response body and parse it

Using the COM proxy classes mentioned above, you can consume SOAP web-services (XML) and REST services (JSON).
The difference between calling SOAP or REST is the different header info you need to set and how to format the request body.

The sample provided here shows the implementation.

Soap Rest Testers.png

FormWindow "SOAP WebServiceTester" will call a public online SOAP web-service.
The request and response is XML.

FormWindow "REST/JSON ServiceTester" calls a public online REST service.
The request and response is JSON.

The sample for SOAP web-services has two implementations using MSXML2_XMLHTTP60 and MSXML2_ServerXMLHTTP60.
The MSXML2_ServerXMLHTTP60 object offers timeout settings and supports the settings for proxies.

The sample is saved in TD2.1 text format and can be used in all subsequent TD versions.

Here you can download the sample:
Down.png WIKI_Consume_REST_SOAP_Services.zip

Pointer2.png How to ignore invalid SSL certificates using MSXML Pointer.png

When a WebSite returns an invalid certificate, you will get a popup window in Internet Explorer where you can ignore the error.
Using MSXML, you can do the same programmatically.

Declare the following constant:


Now, set this option constant for the HTTP object

Function: ExecuteWebService
   Local variables
      MSXML2_ServerXMLHTTP60: uHTTP
      Variant: uVariantOption
      ! Set the option to ignore certificate errors...
      Call uVariantOption.SetNumber( SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS, VT_I4 )
      Call uHTTP.setOption( 2, uVariantOption )
      ! Call the WebService...
      Call uHTTP.send( ... )

Having set the option, errors like

msxml6.dll: The date in the certificate is invalid or has expired
msxml6.dll: Error downloading certificate

will be ignored.