Calling external services

You can use the Hansen.Core.Net.NetService object to call external services from your Infor Public Sector site.

The simplest way to use the NetService object is to write a formula using a service profile. The service profile specifies the details of the web request, such as the host address, the request method, and the response format.

See Service profiles.

You can use the NetService object without a service profile, but in that case you must specify the details of the web request in your code. This example, written in C#, shows how to construct a web request:

public class NetServiceIndexSearcherTests : ServerApplicationTestFixture
{
  int _webRequestConfigKey;

  public NetServiceIndexSearcherTests()
    {
      NewConnectionPerTest = false;
    }
  protected override void OnClassLoad(object source, EventArgs e)
    {
      IWebRequestConfig config = NewComponent<IWebRequestConfig>();
      // Go to openweathermap.org to sign up for an API key (APPID)
      config.HostAddress = "https://api.openweathermap.org/data/2.5/weather?q={{city}}&APPID=xxx";
      config.WebMethod = WebRequestMethod.Get;
      config.Add().Assert();
 
      IWebRequestConfigMapping mapping = NewComponent<IWebRequestConfigMapping>();
      mapping.Source = "$.main.temp";
      mapping.Destination = "Temp";
      mapping.WebRequestConfigKey = config;
      mapping.Add();
 
      _webRequestConfigKey = config.WebRequestConfigKey;
    }

  [Test]
  public void TestSearch()
    {
      IDictionary<string, object> mappings = new Dictionary<string, object>();
      mappings.Add("city", "Sacramento");
 
      IWebRequestDataSource ds = WebRequestDataSource.Create(mappings);
 
      var context = NetService.Send(_webRequestConfigKey, ds);
    }
}