Using service profiles in formulas

In formulas you can use the Send method of the Hansen.Core.Net.NetService object to send web requests to external services via service profiles.

This sample shows how to call an external service using a service profile called "Example":

Dim source As Hansen.Core.Net.IWebRequestDataSource = 
     Hansen.Core.Net.WebRequestDataSource.Create(dictionarySource)
Dim oServiceProfile As Hansen.Core.Net.IServiceProfile = 
     ServerApplication.NewComponent(Of Hansen.Core.Net.IServiceProfile)()
oServiceProfile.ServiceProfileName = "Example"
oServiceProfile.LoadByID().Assert()
Dim context = Hansen.Core.Net.NetService.Send(oServiceProfile.WebRequestConfig)

Note that the sample uses the WebRequestConfig object associated with the service profile. This is where settings such as the host address and the response format are stored.

This sample calls an external service and evaluates the service profile's success conditions:

Dim source As Hansen.Core.Net.IWebRequestDataSource = 
     Hansen.Core.Net.WebRequestDataSource.Create(dictionarySource)
Dim oServiceProfile As Hansen.Core.Net.IServiceProfile = 
     ServerApplication.NewComponent(Of Hansen.Core.Net.IServiceProfile)()
oServiceProfile.ServiceProfileName = "Example"
oServiceProfile.LoadByID().Assert()
Dim context = Hansen.Core.Net.NetService.Send(oServiceProfile.WebRequestConfig)
Dim success = oServiceProfile.WebRequestConfig.EvaluateConditions
     (context.ResponseEntries, source)

This sample calls an external service using a service profile that includes a template variable:

Dim dictionarySource = New Dictionary(Of String, Object)()
dictionarySource.Add("Field2", "Field2Value")
Dim source As Hansen.Core.Net.IWebRequestDataSource = 
     Hansen.Core.Net.WebRequestDataSource.Create(dictionarySource)
Dim oServiceProfile As Hansen.Core.Net.IServiceProfile = 
     ServerApplication.NewComponent(Of Hansen.Core.Net.IServiceProfile)()
oServiceProfile.ServiceProfileName = "Example"
oServiceProfile.LoadByID().Assert()
Dim context = Hansen.Core.Net.NetService.Send(oServiceProfile.WebRequestConfig, source)