InHouse EDI API allows you to run EdiNation's EDI translation and validation API in your own cloud or on-prem environment(s).
This tutorial uses the example Azure Function that comes with the EdiNation Inhouse product, to demonstrate how to publish EdiNation Inhouse API as an Azure Function in your own Azure subscription(s).
The example is for .NET isolated process function.
InHouse API for Azure on GitHub
Prerequisites
To complete this tutorial, you'll need the following:
- Visual Studio 2022, which supports .NET 6.0.
- If you don't have an Azure subscription, create an Azure free account before you begin.
- Download Postman - it's an application to consume/test your API.
- EDI test file(s) - the API supports X12, EDIFACT, EANCOM, HL7, NCPDP, VDA, and EDIGAS. If you don't have a test file, use one of ours - X12 HIPAA, X12, EDIFACT.
Create an Azure Function in the Azure portal
Azure Functions lets you run your code in a serverless environment.
Detailed tutorial on how to create an Azure Function. For this tutorial, we created an Azure Function named "edinationtest".
Select to Publish as Code, Runtime stack .NET, and Version 6:
Then use the default suggestions for the other tabs and finally, Create the function.
Publish the Function from Visual Studio
EdiFabric.Api.dll only works with the edition of EdiFabric.dll included in the solution. Do not install EdiFabric separately from NuGet!
- Download EdiNation Inhouse, unzip it, and navigate to folder edifabric-api-azure.
- Open solution EdiFabric.Api.Azure.sln in Visual Studio 2022.
- Ensure the references to EdiFabric.dll and EdiFabric.Api.dll exist.
-
Open file Configuration.cs and change ApiKey to the API key you received when subscribing to EdiNation InHouse (the existing one is for the free EdiNation plan).
-
Rebuild the solution and ensure all package dependencies were installed correctly.
- Right-click on the project name and select "Publish".
- Publish it to the Azure Function you created in the first step.
Test the Function
-
In the Azure portal, go to your function's overview tab, and copy the function URL:
- Download and open Postman. Let's test the X12 read operation first.
-
Open a new tab in Postman, select the POST method, and add the following request URL (full API reference):
{Your function URL}/api/x12/read
-
Go to the Body tab, select the "binary" content, and browse your text X12/HIPAA file.
If you don't have a test file, use one of ours - X12 HIPAA, X12, EDIFACT.
-
Finally, hit the Send button and inspect the response body:
Troubleshoot
If you receive an error message that begins with any of the below, then your API key wasn't correctly configured or has expired, or you've reached a quota limit:
- One or more errors occurred. (Can't get token!)
-
Transaction set is not supported
Implement distributed cache
For every request to your API, at least two requests are initiated to the cloud EdiNation API - one to acquire a token and another to get the model for your transaction type (if your file contains transactions of different types, such as invoices and purchase orders, then there will be a separate request for each type).
To avoid making these requests, you can implement a distributed cache that can share tokens and models across function invocations. This example uses an Azure Storage Account, containers, and blobs as a distributed cache.
Token cache
To implement the token cache, follow these steps:
-
Create a new Azure Storage Account and copy the connection string.
-
Open the file Configuration.cs and set the AzureStorageConnectionString to the connection string you copied in the previous step.
-
(Optional) In the same file Configuration.cs, change the ContainerName and the BlobName for the token.
-
Open the file EdiFunctions.cs and uncomment all lines that begin with:
BlobCache.Set
-
In the same file EdiFunctions.cs, comment out all lines that begin with:
// SerialKey.Set
- Done! The next time you execute a Lambda function, the token will be loaded from the cache.
Models cache
Let's assume you will be working with files containing X12 transactions of version 4010. By default, every time you execute an operation of the InHouse API, the model for standard X12 and version 4010 is retrieved from the EdiNation API like this:
GET https://api.edination.com/v2/models/EdiNation.X12.ASC.004010
Using a cache will load all models from the cache instead of the EdiNation API.
To implement the models' cache, follow these steps:
-
Go to EdiNation Formats and select the model you will be loading to the cache (in this example, X12 4010).
-
Download the model as a .dll file.
- The file on your disk must be EdiNation.X12.ASC.004010.dll.
-
Go to the Azure Storage Account container that you will use as a cache and upload the file EdiNation.X12.ASC.004010.dll.
-
Open the file Program.cs and uncomment all lines that begin with:
s.AddHostedService<LocalModelsService>
- Done! The next time you execute a Lambda function for X12 4010, the models will be loaded from the cache.
Configure CORS
When you use the in-house edition of EDI Translator you need to configure CORS in the Azure Function.
Go to the CORS tab and set the allowed origins, '*' for any origin.
Finally. save the changes.
Next steps
Learn about the in-house edition of EDI API.
Learn about how to use Inhouse EDI API as AWS Lambda
How to use Inhouse EDI API as an ASP .NET Core application
Comments
0 comments
Please sign in to leave a comment.