A dotnet client for accessing the NHS MESH API
Currently this is not published to any nuget repository.
To use this package within your dotnet solution we suggest using git submodules.
to pull down the repository using git submodules the below command git submodule add https://github.com/NHSDigital/dotnet-mesh-client in the directory you wish to pull down the solution into.
the NHS.Mesh.Client.csproj should then be added to the solution file.
then the client can be added as a project reference to any project which requires it.
The client needs to be registered as a service for Dependency Injection this can be done by using the below code:
the parameters will need to be updated for your specific mailboxes and environments.
the certificate will need to be converted or created as a .pfx file that stores both the certificate and the private key.
the serverSideCertificateCollection should be populated with the certificates of the MESH side server, This is to ensure the host connected to is the expected host.
services.AddMeshClient(_ => _.MeshApiBaseUrl = 'MESHURL')
.AddMailbox("MYMAILBOX",new NHS.MESH.Client.Configuration.MailboxConfiguration
{
Password = "Password",
SharedKey = "SHAREDKEY",
Cert = new X509Certificate2("path to .pfx file","PFX File password"),
serverSideCertCollection = new X509Certificate2Collection()
})
.Build();Multiple mailboxes can be added by including more .AddMailbox methods to the builder and will be resolved when calling the various functions depending on the mailboxId passed to the function.
To use all of the functions the needed service class will need to be injected in to the class which requires them as below To use functions in the mesh Operation Service this needs to injected in the code as below:
public class ExampleService
{
private readonly IMeshOperationService _meshOperationService
public ExampleService(IMeshOperationService meshOperationService)
{
_meshOperationService = meshOperationService;
}
// methods in ExampleService that execute operation service methods.
}The return type from these functions a MeshResponse<T> where T is the successful response data type.
This response also contains an IsSuccessful flag which will indicate is the call to MESH returned a successful response.
If the response is unsuccessful the Error property will contain a APIErrorResponse object that will have further information.
Otherwise the response data will be within the Response property.
To use this inject IMeshOperationService class as shown in Usage.
Use this endpoint to check that MESH can be reached and that the authentication you are using is correct. This endpoint only needs to be called once every 24 hours. This endpoint updates the details of the connection history held for your mailbox and is similar to a keep-alive or ping message, in that it allows monitoring on the Spine to be aware of the active use of a mailbox despite a lack of traffic.
to implement call the
var result = await _meshOperationService.MeshHandshakeAsync(mailboxId);This will return the Mailbox Id.
To use this inject IMeshInboxService class as shown in Usage.
This class contains methods used for receiving messages from MESH.
Returns the message identifier of messages in the mailbox inbox ready for download. to implement call the below:
var result = await _meshInboxService.GetMessagesAsync(mailboxId);this will return a list of MessageIds that are ready to download.
Retrieves a message based on the message identifier obtained from the 'GetMessagesAsync' method. Note this will not retrieve chunked messages.
var result = await _meshInboxService.GetMessageByIdAsync(mailboxId, messageId);The response to this will return a GetMeshResponse Object which will contain a FileAttachment & MessageMetaData
Retrieves a chunked message based on the message identifier obtained from the 'GetMessagesAsync' method.
var result = await _meshInboxService.GetChunkedMessageByIdAsync(mailboxId, messageId);The response to this will return a GetMeshResponse Object which will contain a List<FileAttachment> & MessageMetaData
Note: the list of File Attachments can be passed to the helper method ReassembleChunkedFile as below which will return a File Attachment.
var assembledFile = await FileHelpers.ReassembleChunkedFile(getMessageResponse.Response.FileAttachments);This method will retrieve a message metadata based on the message_id obtained from the 'GetMessagesAsync' method.
var result = await _meshInboxService.GetHeadMessageByIdAsync(mailboxId, messageId);this response will return an object with a MessageMetaData property.
This method will acknowledge the successful download of a message.
var result = await _meshInboxService.AcknowledgeMessageByIdAsync(mailboxId, messageId);this will return the Id of the message acknowledge.
To use this inject IMeshOutboxService class as shown in Usage.
This class contains methods used for sending messages to MESH.
All of the sending methods will expect the below list of parameters
| Parameter Name | Data Type | Required | Description |
|---|---|---|---|
| fromMailboxId | string | Y | Sender mailbox Id |
| toMailboxId | string | Y | Recipient mailbox ID |
| workFlowId | string | Y | Identifies the type of message being sent e.g. Pathology, GP Capitation. |
| file | FileAttachment | Y | contains the details of the file to be sent |
| localId | string | N | local identifier, your reference |
| subject | string | N | additional message subject |
| includeChecksum | bool | N | By default this is false, if true a header will be added with an MD5 Checksum of the file |
There are make tasks for you to configure to run your tests. Run make test to see how they work. You should be able to use the same entry points for local development as in your CI pipeline.
The LICENCE.md file will need to be updated with the correct year and owner
Unless stated otherwise, the codebase is released under the MIT License. This covers both the codebase and any sample code in the documentation.
Any HTML or Markdown documentation is © Crown Copyright and available under the terms of the Open Government Licence v3.0.