Using Web Service Components

Use Web Service components to invoke external SOAP services.

Invoking a cataloged Service

Use the *Service interface to invoke operations on a cataloged Web Service. For example, the following code uses a hypothetical Currency Exchange service:
 // Instantiate a Service component
 // Configuration taken from associated External Resource
 exchange as CurrencyExchangeService = CurrencyExchangeService()

 // Invoke the "getRate" operation
 rate = exchange.getRate(from: "USD", to: "EUR")

Overriding Endpoint configuration

If you use the default constructor of a *Service component, it reads the configuration values from the associated External Resource.

You can override the External Resource configuration passing a String with the URL of the desired endpoint, or passing an object of type Fuego.WebServices.Configuration. For example, the following code uses the hypothetical Currency Exchange service, explicitly defining the endpoint information:
 // Build new WebService configuration: 
 wsConfig = Fuego.WebServices.Configuration()
 exchangeEndPoint = HttpEndpoint("http://localhost:8080/webservices/CurrencyExchange")
 wsConfig.endpoint = exchangeEndPoint

 // Instantiate a Service component, passing a configuration
 // object and ignoring the associated External Resource
 exchange as CurrencyExchangeService = CurrencyExchangeService(wsConfig)

 // Invoke the "getRate" operation
 rate = exchange.getRate(from: "USD", to: "EUR")
Refer to the documentation of Fuego.WebServices.Configuration component for more details.

Handling Exceptions

When a cataloged Web Service component encounters a SOAP fault, it throws a Fuego.WebServices.SoapFaultException that contains the SOAP Fault code and description string.
Important: This exception only covers faults generated by the SOAP protocol. Lower-level network problems and exceptions (like ConnectionException or NoRouteToHostException) are not covered by SoapFaultException.
For example, the following code uses the hypothetical Currency Exchange service, explicitly handling exceptions caused by the component:
do

 // Invoke service
 exchange as CurrencyExchangeService = CurrencyExchangeService()
 rate = exchange.getRate(from: "USD", to: "EUR")

on soapFault as SoapFaultException

    logMessage "SOAP fault caught: ["+ soapFault.faultCode+"] "
               + soapFault.faultString

    logMessage "Fault message:"+generateXmlFor(soapFault)

    // ...
on ex as Exception

    logMessage "Non-SOAP exception calling Web Service "+ex
    // ...
end