Пример #1
0
        public IPotentiallySigned <ServiceMetadata> ParseServiceMetadata(FetcherResponse fetcherResponse)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(fetcherResponse.InputStream);
                var o = ClassFactory.FromXmlStream(fetcherResponse.InputStream);

                X509Certificate signer = null;
                if (o is SignedServiceMetadata)
                {
                    signer = XmldsigVerifier.Verify(doc);
                }

                ServiceInformationType serviceInformation = ((tns.ServiceMetadata)o).ServiceInformation;

                List <ProcessMetadata <Endpoint> > processMetadatas = new List <ProcessMetadata <Endpoint> >();
                foreach (ProcessType processType in serviceInformation.ProcessList.Process)
                {
                    List <Endpoint> endpoints = new List <Endpoint>();
                    foreach (EndpointType endpointType in processType.ServiceEndpointList.Endpoint)
                    {
                        endpoints.Add(
                            Endpoint.Of(
                                TransportProfile.Of(endpointType.TransportProfile),
                                new Uri(endpointType.EndpointURI),
                                this.CertificateInstance(endpointType.Certificate.Data)));
                    }

                    processMetadatas.Add(
                        ProcessMetadata <Endpoint> .Of(
                            ProcessIdentifier.Of(
                                processType.ProcessIdentifier.PrimitiveValue,
                                Scheme.Of(processType.ProcessIdentifier.Scheme)),
                            endpoints));
                }

                return(Signed <ServiceMetadata> .Of(
                           ServiceMetadata.Of(

                               ParticipantIdentifier.Of(
                                   serviceInformation.ParticipantIdentifier.PrimitiveValue,
                                   Scheme.Of(serviceInformation.ParticipantIdentifier.Scheme)),

                               DocumentTypeIdentifier.Of(
                                   serviceInformation.DocumentIdentifier.PrimitiveValue,
                                   Scheme.Of(serviceInformation.DocumentIdentifier.Scheme)),

                               processMetadatas),
                           signer));
            }
            catch (Exception e) when(e is CertificateException | e is IOException)
            {
                throw new Exception(e.Message, e);
            }
        }
Пример #2
0
        public IPotentiallySigned <ServiceMetadata> ParseServiceMetadata(FetcherResponse fetcherResponse)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.PreserveWhitespace = true;
                doc.Load(fetcherResponse.InputStream);
                var o = ClassFactory.FromXmlElement(doc.DocumentElement);

                Xml.Busdox.tns.ServiceMetadata serviceMetadata = o as Xml.Busdox.tns.ServiceMetadata;
                X509Certificate signer = null;
                if (o is SignedServiceMetadata)
                {
                    signer          = XmldsigVerifier.Verify(doc);
                    serviceMetadata = ((SignedServiceMetadata)o).ServiceMetadata;
                }

                if (serviceMetadata == null)
                {
                    throw new LookupException("ServiceMetadata element not found");
                }


                ServiceInformationType serviceInformation = serviceMetadata.ServiceInformation;

                List <ProcessMetadata <Endpoint> > processMetadatas = new List <ProcessMetadata <Endpoint> >();
                foreach (ProcessType processType in serviceInformation.ProcessList.Process)
                {
                    List <Endpoint> endpoints = new List <Endpoint>();
                    foreach (EndpointType endpointType in processType.ServiceEndpointList.Endpoint)
                    {
                        var certificate = this.CertificateInstance(Convert.FromBase64String(endpointType.Certificate));
                        var endpointUri = new Uri(endpointType.EndpointReference.Address.PrimitiveValue);
                        var profile     = TransportProfile.Of(endpointType.TransportProfile);
                        endpoints.Add(Endpoint.Of(profile, endpointUri, certificate));
                    }

                    processMetadatas.Add(
                        ProcessMetadata <Endpoint> .Of(
                            ProcessIdentifier.Of(
                                processType.ProcessIdentifier.PrimitiveValue,
                                Scheme.Of(processType.ProcessIdentifier.Scheme)),
                            endpoints));
                }

                return(Signed <ServiceMetadata> .Of(
                           ServiceMetadata.Of(

                               ParticipantIdentifier.Of(
                                   serviceInformation.ParticipantIdentifier.PrimitiveValue,
                                   Scheme.Of(serviceInformation.ParticipantIdentifier.Scheme)),

                               DocumentTypeIdentifier.Of(
                                   serviceInformation.DocumentIdentifier.PrimitiveValue,
                                   Scheme.Of(serviceInformation.DocumentIdentifier.Scheme)),

                               processMetadatas),
                           signer));
            }
            catch (Exception e) when(e is CertificateException | e is IOException)
            {
                throw new Exception(e.Message, e);
            }
        }