Consuming a web service

Posted by ericg on 03-Aug-2011 14:07

Greetings. Looking for an example to consume a web service from an ABL client. I have the following code but get a SOAP fault, any suggestions or another example. I'm on 10.1C:

DEFINE VARIABLE hWebService AS HANDLE NO-UNDO.

DEFINE VARIABLE hIWeatherForecastService AS HANDLE NO-UNDO.


CREATE SERVER hWebService.


hWebService:CONNECT("-WSDL 'http://www.restfulwebservices.net/wcf/WeatherForecastService.svc?wsdl'").


RUN IWeatherForecastService SET hIWeatherForecastService ON hWebService.


PROCEDURE GetForecastByCity:

  DEFINE INPUT PARAMETER parameters1 AS LONGCHAR NO-UNDO.

  DEFINE OUTPUT PARAMETER parameters2 AS LONGCHAR NO-UNDO.

END PROCEDURE.


DEFINE VARIABLE parameters1 AS LONGCHAR NO-UNDO.

assign parameters1 =

'

<ns0:GetForecastByCity xmlns:ns0="http://www.restfulwebservices.net/ServiceContracts/2008/01">

  <ns0:City>seattle</ns0:City>

  <ns0:Country>us</ns0:Country>

</ns0:GetForecastByCity>

'.


DEFINE VARIABLE parameters2 AS LONGCHAR NO-UNDO.


DEFINE VARIABLE err AS LOGICAL.


RUN GetForecastByCity IN hIWeatherForecastService(INPUT parameters1, OUTPUT parameters2) no-error.

RUN ErrorInfo (OUTPUT err).


/* do something with results */



DELETE PROCEDURE hIWeatherForecastService .

hWebService:DISCONNECT().

DELETE OBJECT hWebService.



PROCEDURE ErrorInfo:

  DEFINE OUTPUT PARAMETER errorfound AS LOGICAL INITIAL FALSE.

  DEFINE VARIABLE k AS INTEGER.

  DEFINE VARIABLE hSOAPFault AS HANDLE.

  DEFINE VARIABLE hSOAPFaultDetail AS HANDLE.

  DEFINE VARIABLE HeaderXML AS LONGCHAR VIEW-AS EDITOR SIZE 52 BY 5 LARGE.


  IF ERROR-STATUS:NUM-MESSAGES > 0 THEN

  DO:

     errorfound = TRUE.

     DO k = 1 TO ERROR-STATUS:NUM-MESSAGES:

        MESSAGE ERROR-STATUS:GET-MESSAGE(k) VIEW-AS ALERT-BOX.

     END.

   

     IF VALID-HANDLE(ERROR-STATUS:ERROR-OBJECT-DETAIL) THEN

     DO:     

       hSOAPFault = ERROR-STATUS:ERROR-OBJECT-DETAIL.

       MESSAGE

       "Fault Code: "   hSOAPFault:SOAP-FAULT-CODE        SKIP

       "Fault String: " hSOAPFault:SOAP-FAULT-STRING      SKIP

       "Fault Actor: "  hSOAPFault:SOAP-FAULT-ACTOR       SKIP

       "Error Type: "   hSOAPFault:TYPE VIEW-AS ALERT-BOX.


       IF VALID-HANDLE(hSOAPFault:SOAP-FAULT-DETAIL) THEN

        DO:

            hSOAPFaultDetail = hSOAPFault:SOAP-FAULT-DETAIL.

            MESSAGE  "Error Type: " hSOAPFaultDetail:TYPE VIEW-AS ALERT-BOX.

            HeaderXML = hSOAPFaultDetail:GET-SERIALIZED().

            DISPLAY HeaderXML LABEL "Serialized SOAP fault detail" WITH FRAME a.

        END.

     END.

  END.

END.

All Replies

Posted by mresnick on 03-Aug-2011 14:23

Eric,

The main issue is that the web service described by this WSDL uses HTTP directly. As the name of the website suggestions the web service uses the REST approach to web services. This approach is an alternative to SOAP based web services.

OpenEdge's web service client supports SOAP based web services. Look for another site that offers SOAP based web services. You might try www.xmethods.net. It's  been a while since I looked at that site so I don't know how useful it is these days.

Michael

Posted by ericg on 03-Aug-2011 15:16

Actually I'm not using the REST format which is at http://www.restfulwebservices.net/rest/WeatherForecastService.svc?wsdl . I'm using their SOAP format.

Posted by mresnick on 03-Aug-2011 15:35

Actually, that WSDL doesn't specify a SOAP binding. In fact, it doesn't specify an HTTP binding either. It's incomplete. The WSDL contains no elements.

The names in the element indicate that there should be an HTTP binding. However there should a element that describes how the web service parameters described in the elements are supposed to be packaged up in to HTTP request and response messages. If both the HTTP and SOAP bindings were supported by this service, there would be two elements in the WSDL. There's a section in the WSDL spec describing what the element would look like for an HTTP binding.

A little background:

In a SOAP binding the element describes how the web services parameters are wrapped in some predefined XML (specifically a element). This predefined XML envelope is then sent using HTTP. As the name implies, the envelope contains some addressing information.

In an HTTP binding the web service parameters aren't wrapped in any extra XML. The HTTP binding is useful for RESTful applications because the addressing information is found in the URL.

Posted by ericg on 03-Aug-2011 16:01

Thanks Michael. I found a running example at http://communities.progress.com/pcom/message/80287#80287. It's specifying the -service and -port switches but they aren't required.

This thread is closed