예제 #1
0
        static void Main(string[] args)
        {
            var xml = new XmlDocument();

            xml.Load(@"SampleData\fminvoice.xml");
            var ehfUtility = new EHFUtility();

            //To validate document using DIFIs validationservice:
            ValidationResult validationResult1 = ehfUtility.ValidateDocument(xml);                                                              //auto-validate
            ValidationResult validationResult2 = ehfUtility.ValidateDocument(xml, PeppolDocumentType.InvoicePeppol4aEHF, UBLVersion.Version20); //validate using given documentType and version

            //Lookup service metadata:
            SmpInformation smpInfo = ehfUtility.LookupSMP("9908:974763907");

            Console.WriteLine("Found accesspoint url for 9908:974763907 at: " + smpInfo.Address);

            //Send invoice (SMP lookup to find correct access point):
            SendResult sendResult = ehfUtility.SendDocument(xml, "9908:453463465", "9908:974763907");

            //Send invoice (override endpoint-address, skipping SMP-lookup):
            var serviceMetadata = ehfUtility.GetServiceMetadataFromKnownEndpoint(); //from app.config
            var createRequest   = GenerateTestRequest(xml, "9908:453463465", "9908:974763907");
            var result2         = ehfUtility.SendDocument(createRequest, "9908:453463465", "9908:974763907", serviceMetadata);

            Console.WriteLine("ok send to test: " + result2.MessageId);
        }
예제 #2
0
        /// <summary>
        /// Lookup SMP (service-metadata) for given participant.
        /// Constructs SMP-url and extracts metadata from SMP (endpointaddress for given participant and receiving-capabilities for that endpoint)
        /// SMP = Service Metadata Provider, See also http://www.peppol.eu/pilot-reporting/infrastructure/post-award-infrastructure-1/smp-providers
        /// </summary>
        /// <param name="participantIdentifier">participant-id, f.eks. 9908:974763907 where 9908 means norway no tax, and 974763907 is org.nr</param>
        /// <returns>Information about the accesspoint for given participant. throws <see cref="SmpLookupException"/> if participant is not found</returns>
        public virtual SmpInformation LookupSMP(string participantIdentifier)
        {
            try
            {
                Log.Info("Start LookupSMP");
                if (string.IsNullOrEmpty(participantIdentifier))
                {
                    throw new ArgumentNullException("participantIdentifier", "cannot be null");
                }

                var helper = new Helper();

                const string businessIdScheme = "iso6523-actorid-upis"; //når vi spør SMP om info MÅ vi bruke denne verdien. Denne betyr at vi bruker en eller annen internasjonal ISO-standard for å definere participant-iden. POLICY 7 XML attributes for Participant Identifiers in BusDox: The “scheme” attribute must be populated with the value "iso6523-actorid-upis" (see POLICY 5) in all instances of the “ParticipantIdentifier” element
                const string documentIdScheme = "busdox-docid-qns";     //denne er alltid fast.. POLICY 10: The PEPPOL document type identifier scheme to be used is: busdox-docid-qns. Applies to: all document type identifiers in all components

                //fungerer: (men då spør vi bare om aksesspunkt som støtter generell type?) Men satser på at det går greit, siden oxalis i hverty fall bare har ett endpoint for alle dokument? trur denne spør om AP godtar fra versjon 1 til 2 og..
                const string documentIdValue = "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:www.cenbii.eu:transaction:biicoretrdm010:ver1.0:#urn:www.peppol.eu:bis:peppol4a:ver1.0::2.0";

                //Participant identifiers – consisting of scheme and value – are encoded as follows into a DNS name: 292 B-<hash-of-value>.<scheme>.<SML-zone-name>
                var smpUrl = helper.BuildSmpUrl(participantIdentifier, businessIdScheme, DefaultSmlDomain);

                try
                {
                    Log.InfoFormat("Contacting SMP URL: {0}", smpUrl);

                    using (var client = new SimpleWebClient())
                    {
                        client.HeadOnly = true;
                        var s1 = client.DownloadString(smpUrl);
                    }

                    Log.Info("SMP OK");
                }
                catch (Exception exception)
                {
                    Log.Error(exception);
                    throw new SmpLookupException(string.Format("Error contacting smpUrl ({0})", smpUrl), smpUrl, exception);
                }

                string endpointAddress;

                try
                {
                    Log.Info("Getting endpointaddres from service metadata..");
                    endpointAddress = helper.GetEndPointAddress(participantIdentifier, businessIdScheme, DefaultSmlDomain, documentIdScheme, documentIdValue);
                    Log.InfoFormat("Endpoint found OK: {0}", endpointAddress);
                }
                catch (Exception exception)
                {
                    Log.Error(exception);
                    throw new SmpLookupException("Error getting endpointaddress from smp: " + exception.Message, smpUrl, exception);
                }

                ServiceGroup serviceGroupElements;

                try
                {
                    Log.Info("Parsing servicegroup-info from smp...");
                    serviceGroupElements = new ServiceGroupParser().GetServiceGroup(smpUrl);
                    Log.Info("Parse OK");
                }
                catch (Exception exception)
                {
                    Log.Error(exception);
                    throw new SmpLookupException("Error getting servicegroups from smp: " + exception.Message, smpUrl, exception);
                }

                var temp = new SmpInformation
                {
                    Address              = endpointAddress,
                    FromSmpUrl           = smpUrl,
                    ServiceGroupElements = serviceGroupElements
                };

                Log.Info("Returning SmpInfo");
                return(temp);
            }
            catch (Exception exception)
            {
                Log.Error(exception);
                throw;
            }
        }