Posted on 14/12/2024 16:50:01
							
							
						 
						Cool, thanks again. We're currently working on extending Connector and plug that into the service. For anyone who needs this in the future, here's how the connector code can look:
  public class MyCustomConnector : Connector
  {
    public override string ProcessRequest(string request)
    {
      var logger = LogManager.GetCurrentClassLogger();
      logger.Info(request);
      var config = (NameValueCollection)ConfigurationManager.GetSection("MyCompanyConnector");
      var url = config["RestUrl"];
      var content = GetJsonContent(request);
      try
      {
        using (var client = new RestClient(GetDefaultHeaders(config)))
        {
          var result = client.PostAsync(url, content).GetAwaiter().GetResult();
          if (result.IsSuccessStatusCode)
          {
            var response = result.Content.ReadAsStringAsync().GetAwaiter().GetResult();
            return response;
          }
          logger.Error($"Error: {result.StatusCode}");
        }
      }
      catch (Exception ex)
      {
        logger.Error($"Error: processing request", ex);
      }
      return "Failed to process request.";
    }
  }
(Still in early demo stages, but this is roughly what it'll eventually do: post to another REST service and return the response.
The connector's DLL is then added to the DynamicWeb service's folder and registered like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="MyCompanyConnector" type="System.Configuration.NameValueSectionHandler"/>
  </configSections>
  <MyCompanyConnector>
    <add key="RestUrl" value="https://example.com"/>
  </MyCompanyConnector>
  <appSettings>
    <add key="ServiceName" value="DynamicwebServiceMyCompany"/>
    <add key="TestMode" value="False"/>
    <add key="TestOutputFile" value="C:\Projects\_temp\Test.xml"/>
    <add key="TestOutputFolder" value="C:\Projects\_temp\TestFiles"/>
    <add key="Secret" value="SecretHere!!"/>
    <add key="WebserviceURI" value="http://localhost:8091/DynamicwebServiceMyCompany"/>
    <add key="DebugInfo" value="True"/>
    <add key="ConnectorType" value="MyCompany.LiveIntegration.Connectors.MyCustomConnector"/>
  </appSettings>
</configuration>
Imar