SendFiles Method

Sends file(s) to the specified server and verify the receipt (if present).

Syntax

async as4client.sendFiles(): Promise<void>

Remarks

SendFiles sends the files specified by EDIData to URL.

Before calling this method set AgreementRef to the agreement identifier used by both parties. Set AS4From and AS4To. Set EDIData specifies the file(s) to be sent. To encrypt the data set RecipientCerts. To sign the data set SigningCert. The SignerCert property should be set to verify the signed receipt.

When this method is called the file(s) will be sent and any returned receipts will be verified.

To indicate a synchronous receipt is expected set ReceiptReplyMode to rrmSync. The following properties are applicable when calling this method with an agreement specifying a synchronous receipt (a receipt provided in the response):

SendFiles Example (synchronous receipt):

client.Profile = As4clientProfiles.ebpfENTSOG;

//Specify the agreement and party information
client.AgreementRef = "http://agreements.company.com/sign_and_encrypt";

client.AS4From.Role = "Sender";
client.AS4From.Id = "org:b2b:example:company:A";

client.AS4To.Role = "Receiver";
client.AS4To.Id = "org:b2b:example:company:B";
      
//Configure the component to expect a synchronous receipt.      
client.ReceiptReplyMode = As4clientReceiptReplyModes.rrmSync;

//Company A's private certificate. Used to sign the outgoing message and files.
client.SigningCert = new Certificate(CertStoreTypes.cstPFXFile, "C:\\files\\CompanyA.pfx", "password", "*");

//Company B's public certificate. Used to encrypt the outgoing file.
client.RecipientCerts.Add(new Certificate("C:\\files\\as4\\CompanyB.cer"));

//Company B's public certificate. Used to verify the signed receipt.
client.SignerCert = new Certificate("C:\\files\\as4\\CompanyB.cer");

client.URL = "http://www.company.com:9090/msh";

EBData data = new EBData();
data.EDIType = "application/edi-x12";
data.Filename = "C:\\files\\myfile.x12";
data.Name = "myfile.x12";

client.EDIData.Add(data);

//Send file(s) and verify the receipt.
client.SendFiles();

The class also supports asynchronous receipts. In this configuration a file is sent from the class to another party, but the receipt is not returned in the response. Instead the other party sends the receipt at a later time. The AS4Server class may be used inside a web page to receive the asynchronous receipt. After receiving the receipt either AS4Server or AS4Client may be used to verify the receipt.

Details about the original message must be stored so that the receipt can be correlated with the message and properly verified. The easiest way to do this is to set AsyncReceiptInfoDir before calling SendFiles. The class will automatically store the required information.

See the VerifyReceipt method of AS4Server for details about verifying asynchronous receipts.

To indicate an asynchronous receipt is expected set ReceiptReplyMode to rrmAsync. The following properties are applicable when calling this method with an agreement specifying a synchronous receipt (a receipt provided in the response):

SendFiles Example (asynchronous receipt):

client.Profile = As4clientProfiles.ebpfENTSOG;

//Specify the agreement and party information
client.AgreementRef = "http://agreements.company.com/sign_and_encrypt_async";

client.AS4From.Role = "Sender";
client.AS4From.Id = "org:b2b:example:company:A";

client.AS4To.Role = "Receiver";
client.AS4To.Id = "org:b2b:example:company:B";
      
//Configure the component to expect a synchronous receipt.      
client.ReceiptReplyMode = As4clientReceiptReplyModes.rrmAsync;

client.AsyncReceiptInfoDir = "C:\\async_info";

//Company A's private certificate. Used to sign the outgoing message and files.
client.SigningCert = new Certificate(CertStoreTypes.cstPFXFile, "C:\\files\\CompanyA.pfx", "password", "*");

//Company B's public certificate. Used to encrypt the outgoing files.
client.RecipientCerts.Add(new Certificate("C:\\files\\as4\\CompanyB.cer"));

//Company B's public certificate. Used to verify the signed receipt.
client.SignerCert = new Certificate("C:\\files\\as4\\CompanyB.cer");

client.URL = "http://www.company.com:9090/msh";

EBData data = new EBData();
data.EDIType = "application/edi-x12";
data.Filename = "C:\\files\\myfile.x12";
data.Name = "myfile.x12";

client.EDIData.Add(data);

//Send file(s).
client.SendFiles();

At this point the file(s) have been sent, but a receipt has not yet been received. AS4Server can be used within a web site to listen for the receipt.

//**** Inside a web site ****
As4server server = new As4server;
server.ReadRequest();

if (!String.IsNullOrEmpty(server.IncomingReceipt.Content))
{
  server.AsyncReceiptInfoDir = "C:\\async_info";
  server.VerifyReceipt();
  //The receipt is now verified
}

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks EDI 2020 JS Edition - Version 20.0 [Build 8162]