How to use MaxMind WSDL Service with gsoap

Building a simple WDSL Client in C.

Start in a new empty directory.

  mkdir ~/mm
  cd ~/mm

Create the C stubs from the wdsl description. ( For c++ just remove the -c option )

    wsdl2h -c -o maxmind_wsdl.h http://www.maxmind.com/app/minfraud_soap_wsdl5
    soapcpp2 -c maxmind_wsdl.h

add a main function

  #include "soapH.h"
  #include "minfraudWebServiceSoap.nsmap"
  int
  main (void)
  {
    struct soap soap;
    struct _ns1__minfraud_USCOREsoap req;
    struct _ns1__minfraud_USCOREsoapResponse res;
  
    soap_init (&soap);
  
    req.i = "24.24.24.24";
    req.domain = "gmx.de";
    req.license_USCOREkey = "xxxx"; /* use illegal license for testing */
  
    if (soap_call___ns1__minfraud_USCOREsoap (&soap, NULL, NULL, &req, &res) ==
        SOAP_OK)
      {
                  /* just print one field -- ist only a example */
        printf ("%s\n", res.minfraud_USCOREoutput->err);
      }
    else
      {
        soap_print_fault (&soap, stderr);
      }
    soap_end (&soap);
    soap_done (&soap);
    return 0;
  }

and finnaly compile it!

   gcc -o mm main.c soapC.c soapClient.c  -lgsoap

great. running it just works. We have a SOAP response. The error from our invalid license key! Perfect.

  ./mm
  License Key Required - visit http://www.maxmind.com/app/ccv2r_signup for free signup

Let gsoap know about our ssl cert

For maxmind's fast server ( minfraud1 ) we need to add a cert that is not part of most distributions. minfraud2 ( www.maxmind.com ) does not need this step.

Get the cert and convert it to PEM ( Useful for every ssl comunication. gsoap or not )

  wget --no-check-certificate https://www.geotrust.com/resources/root_certificates/certificates/Equifax_Secure_Global_eBusiness_CA-1_DER.cer
  openssl x509 -inform DER -in Equifax_Secure_Global_eBusiness_CA-1_DER.cer -out /tmp/mmca.pem -text

append the new cert mmca.pem to you existing cert bundle. For gsoap thats cacerts.pem. If you just want to connect to minfraud1.maxmind.com just use mmca.pem.

Modify the previous example

right after

  soap_init (&soap);

let's gsoap know about ssl and the cert(s) to use. Add the following:

  if (soap_ssl_client_context (&soap,
                               SOAP_SSL_DEFAULT, NULL, NULL, "/tmp/mmca.pem",
                               NULL, NULL))
    {
      soap_print_fault (&soap, stderr);
      exit (1);
    }

then we need to change the url we used in the last example to point to the https port instead http. Change:

  if (soap_call___ns1__minfraud_USCOREsoap (&soap, NULL, NULL, &req, &res)
          == SOAP_OK)

to

  if (soap_call___ns1__minfraud_USCOREsoap
      (&soap, "https://minfraud1.maxmind.com/app/minfraud_soap", NULL, &req,
       &res) == SOAP_OK)

thats all

now compile it.

  gcc -o mmssl -DWITH_OPENSSL mainssl.c soapC.c soapClient.c -lgsoapssl -lssl

Notice, that we have to define WITH_OPENSSL when compiling the sources. And it we must link against libgsoapssl instead of libgsoap.

Here is the full example:

  #include "soapH.h"
  #include "minfraudWebServiceSoap.nsmap"
  int
  main (void)
  {
    struct soap soap;
    struct _ns1__minfraud_USCOREsoap req;
    struct _ns1__minfraud_USCOREsoapResponse res;
  
    soap_init (&soap);
    if (soap_ssl_client_context (&soap,
                               SOAP_SSL_DEFAULT, NULL, NULL, "/tmp/mmca.pem",
                               NULL, NULL))
      {
        soap_print_fault (&soap, stderr);
        exit (1);
      }
  
    req.i = "24.24.24.24";
    req.domain = "gmx.de";
    req.license_USCOREkey = "xxxx"; /* use illegal license for testing */
  
  
    if (soap_call___ns1__minfraud_USCOREsoap
        (&soap, "https://minfraud1.maxmind.com/app/minfraud_soap", NULL, &req,
         &res) == SOAP_OK)
      {
        /* just print one field -- ist only a example */        
        printf ("%s\n", res.minfraud_USCOREoutput->err);
      }
    else
      {
        soap_print_fault (&soap, stderr);
      }
    soap_end (&soap);
    soap_done (&soap);
    return 0;
  
  }

Links ( gsoap, docs, window issues )

http://gsoap2.sourceforge.net/

http://www.cs.fsu.edu/~engelen/soapdoc2.html

For WIN, read this and do not forget to define WITH_OPENSSL http://www.cs.fsu.edu/~engelen/soapdoc2.html#tth_sEc18.24