-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
77 lines (65 loc) · 3.24 KB
/
Program.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Security;
using System.Text;
namespace servicioFaceWCF
{
class Program
{
static void Main(string[] args)
{
EndpointAddress address;
X509Certificate2 serverCertificate;
bool stagingMode = true;
if (stagingMode) //staging mode
{
address = new EndpointAddress(
new Uri("https://se-face-webservice.redsara.es/facturasspp2"),
EndpointIdentity.CreateDnsIdentity("SELLO ENTIDAD SGAD PRUEBAS"));
serverCertificate = new X509Certificate2(@"C:\temp\SELLO-ENTIDAD-SGAD-PRUEBAS.cer");
}
else //production mode
{
address = new EndpointAddress(
new Uri("https://webservice.face.gob.es/facturasspp2"),
EndpointIdentity.CreateDnsIdentity("SELLO DE ENTIDAD SGAD"));
serverCertificate = new X509Certificate2(@"C:\temp\SELLO-DE-ENTIDAD-SGAD.cer");
}
//Our certificate, must be
var clientCertificate = new X509Certificate2(@"C:\temp\myawensomecertificate.pfx", "myawensomepass");
//Custombinding for interop with FACE java web service
CustomBinding customBinding = new CustomBinding();
//security
var sec = SecurityBindingElement.CreateMutualCertificateDuplexBindingElement(
MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10);
sec.AllowSerializedSigningTokenOnReply = true;
sec.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
sec.SecurityHeaderLayout = SecurityHeaderLayout.LaxTimestampLast;
sec.IncludeTimestamp = false;
//message
var textBindingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
//transport
var httpsTransport = new HttpsTransportBindingElement();
httpsTransport.RequireClientCertificate = true;
//Bind in order (Security layer, message layer, transport layer)
customBinding.Elements.Add(sec);
customBinding.Elements.Add(textBindingElement);
customBinding.Elements.Add(httpsTransport);
ChannelFactory<facturasspp2.FacturaSSPPWebServiceProxyPort> factory = new ChannelFactory<facturasspp2.FacturaSSPPWebServiceProxyPort>(customBinding, address);
factory.Credentials.ClientCertificate.Certificate = clientCertificate;
factory.Credentials.ServiceCertificate.DefaultCertificate = serverCertificate;
factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
var service = factory.CreateChannel();
try
{
var c = service.consultarEstados();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}