A .NET application can generate UBL 2.1 documents through a typed object model or templated XML, validate them against the UBL schemas and the PINT AE schematron using an XSLT-based engine, submit them to an Accredited Service Provider through a typed HTTP client with retry policies, and track status in a background hosted service. Keeping the provider behind an interface and using a durable queue (database table, Azure Service Bus or RabbitMQ) gives a system that survives outages and provider changes.
Key facts at a glance
- Generation: typed UBL classes or Razor/XSLT templates producing UBL 2.1.
- Validation: XSD via
XmlReaderSettings; schematron via compiled XSLT 2/3 (e.g. Saxon-HE) or an ISO schematron library. - Submission:
IHttpClientFactory+ Polly retry/circuit breaker. - Background:
IHostedServiceworkers for submission and status polling. - Configuration: provider endpoints and keys in user secrets / Key Vault.
Domain model to UBL
Define an internal EInvoice aggregate independent of both your ERP tables and the UBL schema: parties with TIN, TRN and structured address; lines with quantity, unit code, price, VAT category and reason; allowances and charges; totals computed by a single calculator. Map ERP entities into this aggregate, then serialise the aggregate to UBL. This isolates the awkward parts of legacy tables from the awkward parts of UBL and gives you one place to compute arithmetic correctly.
Validation pipeline
var settings = new XmlReaderSettings { ValidationType = ValidationType.Schema };
settings.Schemas.Add(null, "UBL-Invoice-2.1.xsd");
// ... read document; collect schema errors
var schematron = SchematronCompiler.Compile("PINT-AE.sch"); // once, at startup
var result = schematron.Validate(xmlDocument);
if (result.FatalAssertions.Any()) return ValidationOutcome.Rejected(result);Compile the schematron once and cache it; validation per document then takes milliseconds. Run the same pipeline in unit tests against a corpus of scenario documents.
Submission and status
services.AddHttpClient<IAspClient, ChosenAspClient>()
.AddPolicyHandler(HttpPolicyExtensions.HandleTransientHttpError()
.WaitAndRetryAsync(5, i => TimeSpan.FromSeconds(Math.Pow(2, i))))
.AddPolicyHandler(HttpPolicyExtensions.HandleTransientHttpError()
.CircuitBreakerAsync(5, TimeSpan.FromMinutes(2)));A hosted service dequeues documents, calls SubmitAsync with the document number as idempotency key, records the response, and a second service polls or receives webhooks for status transitions until a terminal state is reached.
Enterprise concerns
| Concern | Approach |
|---|---|
| Multiple legal entities | Tenant context per TIN; separate provider credentials and queues |
| Segregation of duties | Authorization policies for Create vs Release; approvals for thresholds |
| Observability | Structured logs with document ID; metrics for queue age, rejection rate, time-to-accept |
| Archive | Blob storage with immutability policy; hash stored in SQL |
| Provider change | Implement a second IAspClient; switch by configuration |
Where Zaini Developers fits in
We design the compliance layer as a separate service with a clean contract, so your .NET team keeps ownership of the ERP while we deliver and maintain the PINT AE engine, provider adapters and finance dashboard.
Book a free consultation →Frequently asked questions
Is there an official .NET SDK for UAE e-invoicing?
No official SDK. Providers publish REST APIs; the UBL schemas and PINT AE schematron are public standards you implement against.
Can I run schematron natively in .NET?
Yes, by compiling the schematron to XSLT and executing it with an XSLT 2/3-capable processor, or by using a schematron library.
Should I generate XML with XmlSerializer or templates?
Either works. Typed classes reduce ordering errors; templates are quicker to adjust. Validate both ways in CI.
How do I test without production credentials?
Use the provider's sandbox with test identifiers and a mock IAspClient for unit tests.
