Tuesday 18 October 2016

C# Code to test AX document service.

In my previous we created a document service for a custom entity with postal address. In this post I will demonstrate the process to test the same service using visual studio.

Step1: Go-to Inbound port and copy the wsdl url.
 Step2: Go-to the visual studio File --> New --> Project -->Console application


 Step3: Right click  References node and Add new service reference ()





Step4: Paste the below code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestStudentService.StudentServiceReference;//Added namespace o access service in below application

namespace TestStudentService
{
   class Program
{
static void Main(string[] args)
{
AxStudentServiceClient proxy = new AxStudentServiceClient();
// Create an instance of the document class.

AxdAxStudent axdStudent = new AxdAxStudent();
//Create instances of the entities that are used in the service and

// set the needed fields on those entities.
AxdEntity_StudentTable studentTable = new AxdEntity_StudentTable();
studentTable.RollNumber = 28;
studentTable.Name = "Ramesh Kumar";
studentTable.Standard = "Tenth";
//Create a postal address
AxdEntity_DirPartyPostalAddressView address = new AxdEntity_DirPartyPostalAddressView();
address.Street = "2122 NE 5th St Parent ";
address.City = "Beverly Hills";
address.State = "";
address.CountryRegionId = "USA";
address.ZipCode = "90210";
address.Roles = "Home";
AxdEntity_DirPartyContactInfoView electronic = new AxdEntity_DirPartyContactInfoView();
electronic.Locator = "Ajay@upwork.com";
electronic.Type = AxdEnum_LogisticsElectronicAddressMethodType.Email;
electronic.TypeSpecified = true;
electronic.Roles = "Home";
//Add the addresses to the party record and the party to the table record

AxdEntity_DirPartyTable_DirPartyTable dirPartyTable = new AxdEntity_DirPartyTable_DirPartyTable();
dirPartyTable.Name = "Ramesh Kumar";
dirPartyTable.DirPartyPostalAddressView = new AxdEntity_DirPartyPostalAddressView[1] { address };
dirPartyTable.DirPartyContactInfoView = new AxdEntity_DirPartyContactInfoView[1] { electronic };
studentTable.DirPartyTable = new AxdEntity_DirPartyTable_DirPartyTable[1] { dirPartyTable };
axdStudent.StudentTable = new AxdEntity_StudentTable[1] { studentTable };
try

{
// Call the create method on the service passing in the document.
CallContext context = new CallContext();
context.Company = "EAM";
context.Language = "en-au";
EntityKey[] returnFloc = proxy.create(context, axdStudent);
// The create method returns an EntityKey which contains the ID of the sales order.

EntityKey returnedFloc = (EntityKey)returnFloc.GetValue(0);
Console.WriteLine("the student has been created of " + returnedFloc.KeyData[0].Value);
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}    
}
}
}
Step5: Check the record has been created with added information.

In my next post I will demonstrate how to use the update operation on AIF service

No comments:

Post a Comment