Error de seguridad al llamar a un servicio web externo en Visual Studio

Estoy intentando llamar a un servicio web externo en Visual Studio pero recibo el error.

System.Security.SecurityException: solicitud de permiso del tipo 'System.Security.Permissions.SecurityPermission, mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' falló. System.Security.SecurityException: en System.Security.CodeAccessSecurityEngine.Check (demanda de objetos, StackCrawlMark & stackMark, Boolean isPermSet) en System.Security.CodeAccessPermission.Demand () en System.Net.ServicePointManager.set_ServerCertificateValidationCallbackValidationCallidaValida

El siguiente es el programa para invocar el servicio web.

public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction(DataAccess = DataAccessKind.Read)]
    [return: SqlFacet(MaxSize = -1)]
    public static SqlString NYP_RestGet(SqlString uri)
    {
        String document;
        System.Net.ServicePointManager.ServerCertificateValidationCallback +=
        delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                                System.Security.Cryptography.X509Certificates.X509Chain chain,
                                System.Net.Security.SslPolicyErrors sslPolicyErrors)
        {
            return true; // **** Always accept
        };

        // Set up the request, including authentication
        WebRequest req = WebRequest.Create(Convert.ToString(uri));
        ((HttpWebRequest)req).UserAgent = "CLR web client on SQL Server";
        req.ContentType = "application/xml";
        ((HttpWebRequest)req).Accept = "application/xml";

        WebResponse resp = req.GetResponse();
        Stream dataStream = resp.GetResponseStream();
        StreamReader rdr = new StreamReader(dataStream);
        document = (String)rdr.ReadToEnd();


        rdr.Close();
        dataStream.Close();
        resp.Close();
         return (document);
    }
};

Respuestas a la pregunta(1)

Su respuesta a la pregunta