Skip to main content

Generating the Client Classes Programmatically

Generating the Client Classes Programmatically

You can instead generate the client classes programmatically by using the %SOAP.WSDL.ReaderOpens in a new tab class.

The resulting generated classes and their organization may not be the same as if you used the SOAP wizard, which provides greater control over the packages for the generated classes.

To generate the client classes programmatically:

  1. Create an instance of %SOAP.WSDL.ReaderOpens in a new tab.

  2. Optionally set properties to control the behavior of your instance. For details, see the class documentation for %SOAP.WSDL.ReaderOpens in a new tab.

    Note that if the WSDL is at a location that uses SSL, %SOAP.WSDL.ReaderOpens in a new tab (by default) checks whether the certificate server name matches the DNS name used to connect to the server. If these names do not match, the connection is not permitted. This default behavior prevents “man in the middle” attacks and is described in RFC 2818Opens in a new tab, section 3.1; also see RFC 2595Opens in a new tab, section 2.4.

    To disable this check, set the SSLCheckServerIdentity property of the instance equal to 0.

  3. If you need the ability to control the HTTP request in a way that is not directly supported by %SOAP.WSDL.ReaderOpens in a new tab, do this:

    1. Create an instance of %Net.HttpRequestOpens in a new tab and set its properties as needed.

    2. For your instance of %SOAP.WSDL.ReaderOpens in a new tab, set the HttpRequest property equal to the instance of %Net.HttpRequestOpens in a new tab that you just created.

    For example, you might do this if the server requires authentication. See “Providing Login Credentials” in the chapter “Sending HTTP Requests” in Using Caché Internet Utilities.

  4. Invoke the Process() method of your instance:

    method Process(pLocationURL As %String, pPackage As %String = "") as %Status 
    
    • pLocationURL must be the URL of the WSDL of the web service or the name of the WSDL file (including its complete path). Depending on the configuration of the web service, it may be necessary to append a string that provides a suitable username and password; see the examples.

    • pPackage is the name of the package in which to place the generated classes. If you do not specify a package, Caché uses the service name as the package name.

      Note:

      If this package is the same as an existing package, by default the tool overwrites any existing classes that have the same name. To prevent the tool from overwriting a class definition, add the following to that class definition:

      Parameter XMLKEEPCLASS = 1;

The following shows an example Terminal session:

set r=##class(%SOAP.WSDL.Reader).%New() 
GSOAP>set url="http://localhost:57772/csp/gsop/GSOP.AddComplexWS.CLS?WSDL=1"
 
GSOAP>d r.Process(url) 
Compilation started on 11/09/2009 12:53:52 with qualifiers 'dk'
Compiling class AddComplex.ns2.ComplexNumber
Compiling routine AddComplex.ns2.ComplexNumber.1
Compilation finished successfully in 0.170s.
 
Compilation started on 11/09/2009 12:53:52 with qualifiers 'dk'
Compiling class AddComplex.AddComplexSoap
Compiling routine AddComplex.AddComplexSoap.1
Compiling class AddComplex.AddComplexSoap.Add
Compiling routine AddComplex.AddComplexSoap.Add.1
Compilation finished successfully in 0.363s.

The WSDL URL is part of a web application, which might be protected by password authentication. For details on using the WSDL in this case, to generate Caché web clients or third-party web clients, see “Using a Password-Protected WSDL URL,” later in this book.

In all cases, it is also possible to retrieve the WSDL from a browser after supplying the required username and password, save it as a file, and use the file instead.

FeedbackOpens in a new tab