This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Trusted connection from c# code using REST/JSON API

Hi All,

I am a c# developer and my application currently uses PowerShell based Swis integration which I want to replace by REST/JSON API as presented in SwisClient sample..

With PowerShell I can use the syntax "$swis = Connect-Swis -v2 -Trusted -host 10.10.10.1" to create a trusted connection using actual logon credentials.

How can I achieve the same functionality with the c# SwisClient ?

I guess I would need to modify below code, only don't know how :

    private async Task<JToken> SwisCallAsync(Func<HttpClient, Task<HttpResponseMessage>> doRequest)

    {

      var handler = new WebRequestHandler

      {

        Credentials = new NetworkCredential(_username, _password),

        PreAuthenticate = true,

        ServerCertificateValidationCallback = ValidateServerCertificate

      };

      using (var client = new HttpClient(handler))

      {

        client.BaseAddress = new Uri(string.Format("https://{0}:17778/SolarWinds/InformationService/v3/Json/", _hostname));

        HttpResponseMessage response = await doRequest(client);

        var result = JToken.Load(new JsonTextReader(new StreamReader(await response.Content.ReadAsStreamAsync())));

        if (!response.IsSuccessStatusCode)

        {

          throw new ApplicationException(string.Format("Server returned error: {0} {1}{2}{3}", (int)response.StatusCode,

              response.ReasonPhrase, Environment.NewLine, result));

        }

        return result;

      }

    }

Thank you in advance.