IPWorks EDI 2020 JavaScript Edition

Questions / Feedback?

AS4Client Class

Properties   Methods   Events   Configuration Settings   Errors  

The AS4Client class connects to a server to send or receive files.

Syntax

ipworksedi.as4client()

Remarks

The AS4Client component may be used to send or receive files from a server. The component will connect to a server and either send files (push), or request files to download (pull).

Sending Files

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
}

Receiving Files

ReceiveFiles establishes a connection to the server specified by URL and receives files.

The MPC specifies the Message Partition Channel from which messages will be received. The server will reply with files from this channel. If IncomingDirectory is set before calling this method the files will be written to the specified folder, otherwise inspect EDIData to obtain the received file data. The following properties are applicable when calling this method:

After calling this method the following properties will be populated and may be inspected: The Receipt property will be populated with the receipt corresponding to the received message, but it is not yet delivered. The receipt may be delivered by bundling it with another request to receive files, or by calling SendReceipt.

To bundle the receipt with a subsequent ReceiveFiles call the Receipt property must hold the receipt. If the same instance of the class is being used this is already true since Receipt is populated automatically after receiving the file. To use another instance of the class for multiple calls to ReceiveFiles be sure to save the Receipt's ReceiptContent and ReceiptRefToMessageId values for later use.

ReceiveFiles Example:

client.Profile = As4clientProfiles.ebpfENTSOG;

//Company A's private certificate. Used for signing the request.
client.SigningCert = new Certificate(CertStoreTypes.cstPFXFile, "C:\\files\\as4\\CompanyA.pfx", "password", "*");

//Company A's private certificate. Used for decrypting the file.
client.Certificate = new Certificate(CertStoreTypes.cstPFXFile, "C:\\files\\as4\\CompanyA.pfx", "password", "*");

//Company B's public certificate. Used for signature verification.
client.SignerCert = new Certificate("C:\\files\\as4\\CompanyB.cer");

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

//Message Channel id
client.MPC = "mpc_a";

client.IncomingDirectory = "C:\\incoming_dir";
client.ReceiveFiles();

//Inspect client.AgreementRef and other properties for information about the received files
Console.WriteLine(client.AgreementRef);
Console.WriteLine(client.AS4From.Id);
Console.WriteLine(client.AS4To.Id);
Console.WriteLine(client.ConversationId);

//Save the receipt for later use

string receiptContent = client.Receipt.Content;
string receiptRefId = client.Receipt.RefToMessageId;

At this stage the receipt data is saved. Later when making another call to ReceiveFiles and populate the Receipt property with this receipt data. When ReceiveFiles is called again, the receipt for the previous message will be included with the request.

client.Receipt = new EBReceipt(receiptRefId, receiptContent);
client.ReceiveFiles(); //This will now include the bundled receipt

Sending Asynchronous Receipts

SendReceipt sends an asynchronous receipt to the URL.

This method is typically used in conjunction with AS4Server to send an asynchronous receipt after receiving a message. The receipt will be created at the time of the incoming request, then saved for later use. When the receipt is to be sent populate Receipt and call this method.


//Send an asynchronous receipt
client.URL = ""http://www.company.com:9090/msh"";
client.Receipt = new EBReceipt(server.Receipt.RefToMessageId, server.Receipt.Content);
client.ReceiptReplyMode = As4clientReceiptReplyModes.rrmAsync;
client.SendReceipt();

Property List


The following is the full list of the properties of the class with short descriptions. Click on the links for further details.

AgreementRefThe agreement reference.
AS4FromDefines information about the originating party.
AS4ToDefines information about the responding party.
AsyncReceiptInfoDirA directory to hold information used for asynchronous receipt verification.
CertificateThe certificate with private key used for decryption.
CompressionFormatThe compression format (if any) to use.
ConversationIdThe Conversation Id of the message.
CookiesCollection of cookies.
EDIDataThe EDI data.
EncryptionAlgorithmThe algorithm used to encrypt the EDI data.
ErrorsA collection of errors.
FirewallA set of properties related to firewall access.
IncomingDirectoryThe directory to which incoming files are saved.
LocalHostThe name of the local host or user-assigned IP interface through which connections are initiated or accepted.
LogDirectoryThe path to a directory for logging.
LogFileThe log file written.
MessageIdThe unique Id of the message.
MessagePropertiesA collection of message properties.
MPCThe MPC (Message Partition Channel) from which to receive files.
OriginalSOAPMessageThe original SOAP message used to verify the receipt.
OriginalSOAPMessageIdThe original SOAP message Id used to verify the receipt.
ProfileThe AS4 profile.
ProxyA set of properties related to proxy access.
ReceiptThe receipt of a message.
ReceiptReplyModeThe expected receipt reply mode.
RecipientCertsThe public certificate used to encrypt files when sending.
RefToMessageIdSpecifies the RefToMessageId in the message.
ServiceThe service which acts on the message.
ServiceActionThe action within a service that acts on the message.
ServiceTypeThe type of service.
SignatureAlgorithmSignature algorithm to be used in the message.
SignerCertThe public certificate used to verify signatures.
SigningCertThe certificate with private key used to sign messages and files.
SSLAcceptServerCertInstructs the class to unconditionally accept the server certificate that matches the supplied certificate.
SSLCertThe certificate to be used during SSL negotiation.
SSLServerCertThe server certificate for the last established connection.
TimeoutA timeout for the class.
TokenPasswordThe password used in UsernameToken authentication.
TokenPasswordTypeThe password type used in UsernameToken authentication.
TokenUserThe username used in UsernameToken authentication.
URLThe URL to which the request is made.

Method List


The following is the full list of the methods of the class with short descriptions. Click on the links for further details.

ConfigSets or retrieves a configuration setting.
DoEventsProcesses events from the internal message queue.
InterruptInterrupt the current method.
ReceiveFilesConnects to a server to receive files.
ResetResets the state of the control.
SendFilesSends file(s) to the specified server and verify the receipt (if present).
SendReceiptSends an asynchronous receipt.

Event List


The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.

ConnectedFired immediately after a connection completes (or fails).
DisconnectedFired when a connection is closed.
EndTransferFired when a document finishes transferring.
ErrorInformation about errors during data delivery.
HeaderFired every time a header line comes in.
LogFired with log information while processing a message.
RecipientInfoFired for each recipient certificate of the encrypted message.
SetCookieFired for every cookie set by the server.
SignerCertInfoFired during verification of the signed message.
SSLServerAuthenticationFired after the server presents its certificate to the client.
SSLStatusShows the progress of the secure connection.
StartTransferFired when a document starts transferring (after the headers).
TokenAuthenticationFired when the server makes use of UsernameToken authentication.
TransferFired while a document transfers (delivers document).

Configuration Settings


The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.

AgreementRefPModeAgreementRef PMode of message.
AgreementRefTypeThe type of AgreementRef.
AllowWarningsWhether warnings are interpreted as fatal errors.
AttachXMLFilesWhether to send XML files as attachments or within the SOAP body.
AuthorizationThe Authorization string to be sent to the server.
AuthSchemeThe authorization scheme to be used when server authorization is to be performed.
CloseStreamAfterProcessingWhether to close the input or output stream after processing.
CompressXMLPayloadsWhether to compress XML data.
ContentTransferEncodingThe content encoding of the payload data.
DetectDuplicatesWhether to detect duplicate messages when receiving.
EBPrefixSpecifies the prefix to use for messaging.
EDIDataPartId[i]Specified the part Id at the given index.
EncryptionSecurityTokenFormatThe format to use for the security token when encryption.
FilenamePropertyDefines a part property to hold the filename.
ForceSigningCertWhether to force only the SigningCert to be used for signing.
FromId[i]The Id of the party specified by AS4From.
FromIdCountThe number of Ids for the party specified by AS4From.
FromIdType[i]The Id type of the party specified by AS4From.
IdRightA custom Id for the right side of the MessageId.
IncludeHeadersWhether headers are included when posting to a file.
KeyEncryptionAlgorithmThe algorithm used to encrypt the key.
LogLevelThe level of information to log.
LogOptionsThe information to be written to log files.
MessageHeadersReturns the headers of the message.
MessageTypeIndicates the type of message received.
NormalizeIssuerSubjectWhether to normalize the certificate subject within the X509Data element.
OAEPMGF1HashAlgorithmThe MGF1 hash algorithm used when encrypting a key.
OAEPParamsThe hex encoded OAEP parameters to be used when encrypting a key.
OAEPRSAHashAlgorithmThe RSA hash algorithm used when encrypting a key.
PasswordA password if authentication is to be used.
PostToFileCreates the message on disk.
PullActionThe Action to use with selective message pulling.
PullAgreementRefThe AgreementRef to use with selective message pulling.
PullRefToMessageIdThe RefToMessageId to use with selective message pulling.
PullServiceThe Service to use with selective message pulling.
PullServiceTypeThe ServiceType to use with selective message pulling.
ReferenceHashAlgorithmThe hash algorithm used to has the data specified in the reference of a signature.
RequireEncryptionWhether encryption is required when processing received messages.
RequireSignatureWhether a signature is required when processing received messages.
ResponseFileA file from which to read the response.
ResponseHeadersThe headers for the AS4 response message.
SignerCACertThe CA certificates that issued the signer certificate.
SigningSecurityTokenFormatThe format to use for the security token when signing.
TempPathWhere temporary files are optionally written.
ToId[i]The Id of the party specified by AS4To.
ToIdCountThe number of Ids for the party specified by AS4To.
ToIdType[i]The Id type of the party specified by AS4To.
TransformReceiptWhether to canonicalize the received receipt.
UseNonceWhether to use a nonce in UsernameToken authentication.
UserA user name if authentication is to be used.
AcceptEncodingUsed to tell the server which types of content encodings the client supports.
AllowHTTPCompressionThis property enables HTTP compression for receiving data.
AllowHTTPFallbackWhether HTTP/2 connections are permitted to fallback to HTTP/1.1.
AppendWhether to append data to LocalFile.
AuthorizationThe Authorization string to be sent to the server.
BytesTransferredContains the number of bytes transferred in the response data.
ChunkSizeSpecifies the chunk size in bytes when using chunked encoding.
CompressHTTPRequestSet to true to compress the body of a PUT or POST request.
EncodeURLIf set to true the URL will be encoded by the class.
FollowRedirectsDetermines what happens when the server issues a redirect.
GetOn302RedirectIf set to true the class will perform a GET on the new location.
HTTP2HeadersWithoutIndexingHTTP2 headers that should not update the dynamic header table with incremental indexing.
HTTPVersionThe version of HTTP used by the class.
IfModifiedSinceA date determining the maximum age of the desired document.
KeepAliveDetermines whether the HTTP connection is closed after completion of the request.
KerberosSPNThe Service Principal Name for the Kerberos Domain Controller.
LogLevelThe level of detail that is logged.
MaxRedirectAttemptsLimits the number of redirects that are followed in a request.
NegotiatedHTTPVersionThe negotiated HTTP version.
OtherHeadersOther headers as determined by the user (optional).
ProxyAuthorizationThe authorization string to be sent to the proxy server.
ProxyAuthSchemeThe authorization scheme to be used for the proxy.
ProxyPasswordA password if authentication is to be used for the proxy.
ProxyPortPort for the proxy server (default 80).
ProxyServerName or IP address of a proxy server (optional).
ProxyUserA user name if authentication is to be used for the proxy.
SentHeadersThe full set of headers as sent by the client.
StatusLineThe first line of the last response from the server.
TransferredDataThe contents of the last response from the server.
TransferredDataLimitThe maximum number of incoming bytes to be stored by the class.
TransferredHeadersThe full set of headers as received from the server.
TransferredRequestThe full request as sent by the client.
UseChunkedEncodingEnables or Disables HTTP chunked encoding for transfers.
UseIDNsWhether to encode hostnames to internationalized domain names.
UserAgentInformation about the user agent (browser).
ConnectionTimeoutSets a separate timeout value for establishing a connection.
FirewallAutoDetectTells the class whether or not to automatically detect and use firewall system settings, if available.
FirewallHostName or IP address of firewall (optional).
FirewallPasswordPassword to be used if authentication is to be used when connecting through the firewall.
FirewallPortThe TCP port for the FirewallHost;.
FirewallTypeDetermines the type of firewall to connect through.
FirewallUserA user name if authentication is to be used connecting through a firewall.
KeepAliveIntervalThe retry interval, in milliseconds, to be used when a TCP keep-alive packet is sent and no response is received.
KeepAliveTimeThe inactivity time in milliseconds before a TCP keep-alive packet is sent.
LingerWhen set to True, connections are terminated gracefully.
LingerTimeTime in seconds to have the connection linger.
LocalHostThe name of the local host through which connections are initiated or accepted.
LocalPortThe port in the local host where the class binds.
MaxLineLengthThe maximum amount of data to accumulate when no EOL is found.
MaxTransferRateThe transfer rate limit in bytes per second.
ProxyExceptionsListA semicolon separated list of hosts and IPs to bypass when using a proxy.
TCPKeepAliveDetermines whether or not the keep alive socket option is enabled.
TcpNoDelayWhether or not to delay when sending packets.
UseIPv6Whether to use IPv6.
LogSSLPacketsControls whether SSL packets are logged when using the internal security API.
OpenSSLCADirThe path to a directory containing CA certificates.
OpenSSLCAFileName of the file containing the list of CA's trusted by your application.
OpenSSLCipherListA string that controls the ciphers to be used by SSL.
OpenSSLPrngSeedDataThe data to seed the pseudo random number generator (PRNG).
ReuseSSLSessionDetermines if the SSL session is reused.
SSLAcceptAnyServerCertWhether to trust any certificate presented by the server.
SSLCACertsA newline separated list of CA certificate to use during SSL client authentication.
SSLCipherStrengthThe minimum cipher strength used for bulk encryption.
SSLEnabledCipherSuitesThe cipher suite to be used in an SSL negotiation.
SSLEnabledProtocolsUsed to enable/disable the supported security protocols.
SSLEnableRenegotiationWhether the renegotiation_info SSL extension is supported.
SSLIncludeCertChainWhether the entire certificate chain is included in the SSLServerAuthentication event.
SSLNegotiatedCipherReturns the negotiated ciphersuite.
SSLNegotiatedCipherStrengthReturns the negotiated ciphersuite strength.
SSLNegotiatedCipherSuiteReturns the negotiated ciphersuite.
SSLNegotiatedKeyExchangeReturns the negotiated key exchange algorithm.
SSLNegotiatedKeyExchangeStrengthReturns the negotiated key exchange algorithm strength.
SSLNegotiatedVersionReturns the negotiated protocol version.
SSLProviderThe name of the security provider to use.
SSLSecurityFlagsFlags that control certificate verification.
SSLServerCACertsA newline separated list of CA certificate to use during SSL server certificate validation.
TLS12SignatureAlgorithmsDefines the allowed TLS 1.2 signature algorithms when UseInternalSecurityAPI is True.
TLS12SupportedGroupsThe supported groups for ECC.
TLS13KeyShareGroupsThe groups for which to pregenerate key shares.
TLS13SignatureAlgorithmsThe allowed certificate signature algorithms.
TLS13SupportedGroupsThe supported groups for (EC)DHE key exchange.
AbsoluteTimeoutDetermines whether timeouts are inactivity timeouts or absolute timeouts.
FirewallDataUsed to send extra data to the firewall.
InBufferSizeThe size in bytes of the incoming queue of the socket.
OutBufferSizeThe size in bytes of the outgoing queue of the socket.
BuildInfoInformation about the product's build.
CodePageThe system code page used for Unicode to Multibyte translations.
LicenseInfoInformation about the current license.
UseInternalSecurityAPITells the class whether or not to use the system security libraries or an internal implementation.

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