コード例 #1
0
        public static string CallCreate(ChannelFactory <Resource> resourceFactory, Uri thisUrl, string smlDomain, int assuranceLevel, CreateRequest request, IMessageMetadata messageMetadata)
        {
            STARTLibrary.accesspointService.Resource ws = null;

            try
            {
                var serviceMetadata = !string.IsNullOrEmpty(smlDomain) ?
                                      ServiceMetadata.FromSml(smlDomain, request) :
                                      ServiceMetadata.FromKnownEndpoint(resourceFactory);

                //NOTE: if you want to debug and send to "wrong" address, change below:
                //var test1 = ServiceMetadata.FromSml(smlDomain, request); //henter metadata fra SML
                //var test2 = ServiceMetadata.FromKnownEndpoint(resourceFactory);
                //var test3 = new ServiceMetadata()
                //    {
                //        Address = new Uri("https://ehf.fylkesmannen.no/oxalis"), //factory.Endpoint.Address.Uri,
                //        Certificate = resourceFactory.Credentials.ServiceCertificate.DefaultCertificate
                //    };
                //serviceMetadata = test1;

                if (serviceMetadata.Certificate == null)
                {
                    throw new ArgumentException("Certificate required (both for custom validation and for authenticationMode \"MutualCertificate\").");
                }

                SetExpectedServiceCertificate(resourceFactory, serviceMetadata.Certificate);

                X509Certificate2 clientCertificate = resourceFactory.Credentials.ClientCertificate.Certificate;

                Saml2SecurityToken token = AccessPointToken.ClaimsToSaml2SenderVouchesToken(
                    AccessPointToken.MakeClaims(request.SenderIdentifier.Value, assuranceLevel),
                    thisUrl.AbsoluteUri, clientCertificate);

                //NOTE: changed when upgrading to .NET 4.5:
                //ws = resourceFactory.CreateChannelWithIssuedToken(new EndpointAddress(thisUrl, resourceFactory.Endpoint.Address.Identity), token);
                ws = resourceFactory.CreateChannelWithIssuedToken(token, new EndpointAddress(thisUrl, resourceFactory.Endpoint.Address.Identity));

                var response = ws.Create(request);
                return("Document sent.");
            }
            catch (Exception exception)
            {
                throw exception;
            }
            finally
            {
                if (ws is IDisposable)
                {
                    (ws as IDisposable).Dispose();
                }
            };
        }
コード例 #2
0
        public static string CallCreate(ChannelFactory <STARTLibrary.accesspointService.Resource> resourceFactory,
                                        Uri thisUrl, string smlDomain, int assuranceLevel, CreateRequest request)
        {
            STARTLibrary.accesspointService.Resource ws = null;

            Helper help = new Helper();

            try
            {
                ServiceMetadata metadata = !string.IsNullOrEmpty(smlDomain) ?
                                           ServiceMetadata.FromSml(smlDomain, request) :
                                           ServiceMetadata.FromKnownEndpoint(resourceFactory);
                if (metadata.Certificate == null)
                {
                    throw new ArgumentException("Certificate required (both for custom validation and for authenticationMode \"MutualCertificate\").");
                }

                SetExpectedServiceCertificateNew(resourceFactory, metadata.Certificate);

                X509Certificate2 clientCertificate = resourceFactory.Credentials.ClientCertificate.Certificate;

                Saml2SecurityToken token = AccessPointToken.ClaimsToSaml2SenderVouchesToken(
                    AccessPointToken.MakeClaims(request.SenderIdentifier.Value, assuranceLevel),
                    thisUrl.AbsoluteUri, clientCertificate);

                ws = resourceFactory.CreateChannelWithIssuedToken(new EndpointAddress(thisUrl, resourceFactory.Endpoint.Address.Identity), token);

                ws.Create(request);
                return("Document sent.");
            }
            catch (Exception)
            {
                throw help.MakePeppolException("bden:ServerError", "ServerError");
            }
            finally
            {
                if (ws is IDisposable)
                {
                    (ws as IDisposable).Dispose();
                }
            };
        }