Error initializing the HttpClient variable

367 Views Asked by At

I am trying to call a web service from the c# application and I am getting error when I am initializing the HttpClient variable

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Configuration;
using System.Net.Http.Headers;
using System.Text;
using System.IO;
using System.Net.Security;
using System.Xml;
using System.Xml.Linq;
using System.Threading.Tasks;

namespace interfacing
{
   public class APICall
   {
        string BaseURL_L = ConfigurationManager.AppSettings["BaseURL"];
        using(var lab = new HttpClient())
        {    
             ServicePointManager.ServerCertificateValidationCallback = 
                 new RemoteCertificateValidationCallback(delegate { return true; });

Getting error in using statement

The contextual keyword 'var' may only appear within a variable declaration or in script code

Also getting error

The name 'ServicePointManager.ServerCertificateValidationCallback' does not exist in the current context.

.RemoteCertificateValidationCallback()' must declare a body because it is not marked abstract, extern, or partial

Not sure what I am missing here. I have all the above references.

0

There are 0 best solutions below