public List <ServiceReference> ParseServiceGroup(FetcherResponse fetcherResponse) // throws LookupException { try { ServiceGroup serviceGroup = new ServiceGroup(); serviceGroup.FromXmlStream(fetcherResponse.InputStream); List <ServiceReference> serviceReferences = new List <ServiceReference>(); foreach (ServiceMetadataReferenceType reference in serviceGroup.ServiceMetadataReferenceCollection.ServiceMetadataReference) { string hrefDocumentTypeIdentifier = WebUtility.UrlDecode(reference.Href).Split(new[] { "/services/" }, StringSplitOptions.None)[1]; string[] parts = hrefDocumentTypeIdentifier.Split(new[] { "::" }, 2, StringSplitOptions.None); try { serviceReferences.Add( ServiceReference.Of( DocumentTypeIdentifierWithUri.Of( parts[1], Scheme.Of(parts[0]), new Uri(reference.Href)))); } catch (Exception) { Logger.WarnFormat("Unable to parse '{0}'.", hrefDocumentTypeIdentifier); } } return(serviceReferences); } catch (Exception e) { throw new LookupException(e.Message, e); } }
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); } }
public FetcherResponse Detect(FetcherResponse fetcherResponse) // throws LookupException { try { byte[] fileContent = fetcherResponse.InputStream.ToBuffer(); String ns = XmlUtils.ExtractRootNamespace(Encoding.UTF8.GetString(fileContent)); if (ns != null) { return(new FetcherResponse(fileContent.ToStream(), ns)); } throw new LookupException("Unable to detect namespace."); } catch (IOException e) { throw new LookupException(e.Message, e); } }
public IPotentiallySigned <ServiceMetadata> ParseServiceMetadata(FetcherResponse fetcherResponse) { FetcherResponse response = fetcherResponse; if (response.Namespace == null) { response = this.Detect(response); } foreach (IMetadataReader metadataReader in this.metadataReaders) { NamespaceAttribute nsAttr = (NamespaceAttribute)metadataReader.GetType().GetCustomAttribute(typeof(NamespaceAttribute), true); if (nsAttr.Value.EqualsIgnoreCase(response.Namespace)) { return(metadataReader.ParseServiceMetadata(response)); } } throw new LookupException(String.Format("Unknown namespace: {0}", response.Namespace)); }
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); } }
public List <ServiceReference> ParseServiceGroup(FetcherResponse fetcherResponse) // throws LookupException { throw new NotSupportedException("service group not managed for BUSDOX"); }