This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClass1.cs
52 lines (40 loc) · 2.38 KB
/
Class1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using GeneXus.Programs;
using GeneXus.Utils;
public class GxSoapHandler
{
public void Setup(string eoName, GxLocation loc, object serviceClient)
{
String Parameters = loc.Configuration.ToString();
string[] Parameter = Parameters.Split(';');
String IdentStr = Parameter[1];
String DGICert = Parameter[2];
String ClientCert = Parameter[3];
String Clientpassword = Parameter[4];
String ServUri = Parameter[5];
if (eoName == "WS_eFactura") // Este es el nombre del external object para filtrar, en este ejemplo EfacturaUy
{
// Aca se implementa la configuracion del serviceClient segun corresponda, por ejemplo:
ClientBase<ISdtWS_eFactura> svc = serviceClient as ClientBase<ISdtWS_eFactura>;
//Seteo el protection level por programa
svc.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign;
//Declaro el objeto donde voy a guardar el Certificado desde el path del archivo, Cliente y DGI
System.Security.Cryptography.X509Certificates.X509Certificate2 crtCLI;
System.Security.Cryptography.X509Certificates.X509Certificate2 crtDGI;
crtCLI = new System.Security.Cryptography.X509Certificates.X509Certificate2(ClientCert.Trim(), Clientpassword.Trim());
crtDGI = new System.Security.Cryptography.X509Certificates.X509Certificate2(DGICert.Trim());
//Seteo al WS los certificados
svc.ClientCredentials.ClientCertificate.Certificate = crtCLI;
svc.ClientCredentials.ServiceCertificate.DefaultCertificate = crtDGI;
svc.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
//Creo la direccion del WS, que tiene la URI y el DNS(es el CN del certificado de la DGI)
svc.Endpoint.Address = new System.ServiceModel.EndpointAddress(new Uri(ServUri.Trim()),
EndpointIdentity.CreateDnsIdentity(IdentStr.Trim()));
}
}
}