NetReceiveAssociateRequest Example for C#

//This example uses the predefined variable “List2” of type “ListBox” from “.NET Framework”.
//LEADDICOMNet1 is a predefined LEADDicomNet object
private void LEADDICOMNet1_NetReceiveAssociateRequest(int hNet, int hPDU)
{
   int x = 0;
   short nID = 0;
   short nResult = 0;
   string szAbstract = null;
   string szTransfer = null;
   //we have received an AssociateRequest
   List2.Items.Add("Associate Request was received");
   //check the version, if not 1, reject it
   if (LEADDICOMNet1.GetVersion(hPDU) != 1)
      LEADDICOMNet1.SendAssociateReject(hNet, (short)LTDNCLib.AssociateRejectConstants.PDU_REJECT_RESULT_PERMANENT, (short)LTDNCLib.AssociateRejectConstants.PDU_REJECT_SOURCE_USER, (short)LTDNCLib.AssociateRejectConstants.PDU_REJECT_REASON_UNKNOWN);
   else
   {
      //send associate accept class back
      LEADDICOMNet1.CreateAssociate(false);
      LEADDICOMNet1.ResetAssociate(LEADDICOMNet1.hPDU, false);
      //copy all presentation objects from received hPDU
      //also, reply that we only support the first Transfer Syntax from the received hPDU
      for (x = 0; x < LEADDICOMNet1.GetPresentationCount(hPDU); x++)
      {
         nID = LEADDICOMNet1.GetPresentationID(hPDU, x);
         szTransfer = LEADDICOMNet1.GetTransferSyntax(hPDU, nID, 0);
         nResult = (short)LTDNCLib.AssociateAcceptConstants.PDU_ACCEPT_RESULT_SUCCESS;
         szAbstract = LEADDICOMNet1.GetPresentationAbstract(hPDU, nID);
         LEADDICOMNet1.AddPresentation(LEADDICOMNet1.hPDU, nID, nResult, szAbstract);
         LEADDICOMNet1.AddTransferSyntax(LEADDICOMNet1.hPDU, nID, szTransfer);
      }
      LEADDICOMNet1.SendAssociateAccept(hNet);
      LEADDICOMNet1.FreeAssociate(LEADDICOMNet1.hPDU);
   }
}