Καλησπέρα,
Εχω φτιάξει ένα CLR Assembly το οποίο καλεί ένα web service μέσω http.
====================================================================
namespace BusinessDaysCalc
{
public partial class UserDefinedFunctions
{
[SqlFunction(DataAccess = DataAccessKind.Read)]
public static SqlDateTime CalcBusinessDays(SqlInt32 month, SqlInt32 year, SqlInt32 daysInc)
{
// Read the URL of web service
var wsCaller = Common.RetWsKondorPlus();
if (string.IsNullOrEmpty(wsCaller) || wsCaller.StartsWith("ERROR"))
return (SqlDateTime.Null);
// Set always to accept certificates
// System.Net.ServicePointManager.ServerCertificateValidationCallback +=
// (sender, certificate, chain, sslPolicyErrors) => (true);
// Initialize web service
var service = new WebServiceKondorPlus.Service {Url = wsCaller};
// Call the web service
var dt = service.GetBusinessDate(month.Value, year.Value, daysInc.Value);
return new SqlDateTime(dt);
}
};
}
====================================================================
Οταν το καλέσω μέσω https://.... μου βγάζει το παρακάτω μήνυμα:
Msg 6522, Level 16, State 1, Line 2
A .NET Framework error occurred during execution of user-defined routine or aggregate "ufnCalcBusinessDays":
System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
System.Security.Authentication.AuthenticationException:
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncPro
...
System.Net.WebException:
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at BusinessDaysCalc.WebServiceKondorPlus.Service.GetBusinessDate(Int32 month, Int32 year, Int32 daysInc)...
Ενεργοποιόντας την εντολή να αγνοεί το certificate:
System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => (true);
Λαμβάνω το παρακάτω μήνυμα:
Msg 6522, Level 16, State 1, Line 2
A .NET Framework error occurred during execution of user-defined routine or aggregate "ufnCalcBusinessDays":
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
System.Security.SecurityException:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Net.ServicePointManager.set_ServerCertificateValidationCallback(RemoteCertificateValidationCallback value)
at BusinessDaysCalc.UserDefinedFunctions.CalcBusinessDays(SqlInt32 month, SqlInt32 year, SqlInt32 daysInc)
Ο ίδιος κώδικας εάν τρέξει σε console application ή web application μέσω SSL (https://...) τρέχει χωρίς πρόβλημα.
Εχει αντιμετωπίσει κάποιος άλλος το συγκεκριμένο πρόβλημα;