Consuming AIF document service from C#

For create:

static void Main(string[] args)
{
//Working One
//Create the client object and context
EAMTerminalGroupLocationServiceClient client = new EAMTerminalGroupLocationServiceClient();

// Create an instance of the document class.
AxdEAMTerminalGroupLocation TerminalGrpLocation = new AxdEAMTerminalGroupLocation();

CallContext context = new CallContext();
context.Company = “EAM”;

// Create instances of the entities that are used in the service and
// set the needed fields on those entities.
AxdEntity_FunctionalLoc funcLoc = new AxdEntity_FunctionalLoc();

funcLoc.FunctionalLocationID = “308”;
funcLoc.Name = “Testing_FL”;
funcLoc.FunctionalLocationType = “2”;
funcLoc.ParentFunctionalLocation = “Test”;

/*AxdEntityKey_MROParmStageFunctionalLocation funcLocstg = new AxdEntityKey_MROParmStageFunctionalLocation();

funcLocstg.StageID = “NEW”;

funcLoc.Stage = funcLocstg;*/

/*AxdEntity_FunctionalExt funcExt = new AxdEntity_FunctionalExt();

funcLoc.FunctionalExt = new AxdEntity_FunctionalExt[1] { funcExt };*/

AxdEntity_ObjectTable objectTable = new AxdEntity_ObjectTable();

objectTable.ObjectID = “224”;
objectTable.ObjectType = “1000”;
objectTable.Name = “Test_Object”;

AxdEntity_FuncLocObject funcLocObj = new AxdEntity_FuncLocObject();

objectTable.FuncLocObject = new AxdEntity_FuncLocObject[1] { funcLocObj };

AxdEntity_ObjectSpec objSpec = new AxdEntity_ObjectSpec();

objSpec.SpecificationTypeId = “POSITION_ID”;
objSpec.ValueString = “123”;

objectTable.ObjectSpec = new AxdEntity_ObjectSpec[1] { objSpec };

funcLoc.ObjectTable = new AxdEntity_ObjectTable[1] { objectTable };

TerminalGrpLocation.FunctionalLoc = new AxdEntity_FunctionalLoc[1] { funcLoc };

try
{
EntityKey[] returnFloc = client.create(context, TerminalGrpLocation);

// The create method returns an EntityKey which contains the ID of the sales order.
EntityKey returnedFloc = (EntityKey)returnFloc.GetValue(0);
Console.WriteLine(“the TGL has been created of ” + returnedFloc.KeyData[0].Value);
Console.ReadLine();
}

catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}
}

 

Create or update which includes party:

class Program
{
//Working one provided for release 3
static void Main(string[] args)
{
//Create(“2701”);
Update(“2700”);
}
static void Create(string _funcLocId)
{
EAMAxdFunctionalLocationServiceClient proxy = new EAMAxdFunctionalLocationServiceClient();

try
{
// Create an instance of the document class.
AxdEAMAxdFunctionalLocation Floc = new AxdEAMAxdFunctionalLocation();

//Create instances of the entities that are used in the service and set the needed fields on those entities.

AxdEntity_FunctionaLoc omrLocationTable = new AxdEntity_FunctionaLoc();
omrLocationTable.FunctionalLocationID = _funcLocId;
omrLocationTable.FunctionalLocationType = “2”;
omrLocationTable.Name = “Swanston Street”;

//Incase if you want to test the negative case scenario by providing stage then the instance relation type is mandatory
//else an error would be thrown as “The value in field Stage is invalid.”
AxdEntityKey_MROParmStageFunctionalLocation stage = new AxdEntityKey_MROParmStageFunctionalLocation();
stage.StageID = “OPERATIONAL”;
stage.InstanceRelationType = 105527;

omrLocationTable.Stage = stage;

AxdEntity_DirPartyTable_DirPartyTable party = new AxdEntity_DirPartyTable_DirPartyTable();
party.NameAlias = “Fred Blogs”;
party.Name = “Fred Blogs”;

//Create a postal address
AxdEntity_AddressView address = new AxdEntity_AddressView();
address.Street = “2122 NE 5th St Parent “;
address.City = “Arlington Heights”;
address.State = “”;
address.CountryRegionId = “USA”;
address.ZipCode = “60004”;
address.Roles = “Home”;

AxdEntity_ContactView electronic = new AxdEntity_ContactView();
electronic.Locator = “myki@ptv.com”;
electronic.Type = AxdEnum_LogisticsElectronicAddressMethodType.Email;
electronic.TypeSpecified = true;
electronic.Roles = “Home”;

////Add the addresses to the party record and the party to the extension table record
AxdEntity_FunctionaLocExt extension = new AxdEntity_FunctionaLocExt();
AxdEntity_DirPartyTable_DirPartyTable dirPartyTable = new AxdEntity_DirPartyTable_DirPartyTable();
dirPartyTable.Name = “Fred Blogs”;
dirPartyTable.AddressView = new AxdEntity_AddressView[1] { address };
dirPartyTable.ContactView = new AxdEntity_ContactView[1] { electronic };

//Assigning Service provider
extension.ServiceProvider = 318;
extension.ServiceProviderSpecified = true;
extension.DirPartyTable = new AxdEntity_DirPartyTable_DirPartyTable[1] { dirPartyTable };

omrLocationTable.FunctionaLocExt = new AxdEntity_FunctionaLocExt[1] { extension };

AxdEntity_AddressView[] addresses = new AxdEntity_AddressView[] { address };

Floc.FunctionaLoc = new AxdEntity_FunctionaLoc[] { omrLocationTable };
proxy.Open();
// 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, Floc);

AxdEAMAxdFunctionalLocation result = proxy.read(context, returnFloc);
if (result != null)
{
Console.WriteLine(“Read the record”);
}

// The create method returns an EntityKey which contains the ID of the sales order.
EntityKey returnedFloc = (EntityKey)returnFloc.GetValue(0);
Console.WriteLine(“Funtional location has been created of ” + returnedFloc.KeyData[0].Value);
Console.ReadLine();
}

catch (Exception e)
{
string message = e.Message;
if (e.InnerException != null)
message += “Inner exception:” + e.InnerException.Message;
Console.WriteLine(message);
Console.ReadLine();
}
finally
{
if (proxy != null)
{
if (proxy.State == System.ServiceModel.CommunicationState.Faulted)
proxy.Abort();
else if (proxy.State != System.ServiceModel.CommunicationState.Closed)
proxy.Close();
}
}
}
static void Update(string _funcLocId)
{
EAMAxdFunctionalLocationServiceClient client = null;

try
{
QueryCriteria criteria = new QueryCriteria()
{
CriteriaElement = new CriteriaElement[]
{
new CriteriaElement()
{
DataSourceName = “FunctionaLoc”,
FieldName = “FunctionalLocationID”,
Operator = Operator.Equal,
Value1 = _funcLocId
}
}
};
CallContext context = new CallContext();
context.Company = “EAM”;
context.Language = “en-AU”;

client = new EAMAxdFunctionalLocationServiceClient();
client.Open();
EntityKey[] keys = client.findKeys(context, criteria);
if (keys != null && keys.Length > 0)
{
AxdEAMAxdFunctionalLocation funcLocDoc = client.read(context, keys);

if (funcLocDoc != null && funcLocDoc.FunctionaLoc != null)
{

AxdEntity_FunctionaLoc funcLoc = funcLocDoc.FunctionaLoc.First();
funcLoc.Name = “SUPERB”;
funcLoc.action = AxdEnum_AxdEntityAction.update;
funcLoc.actionSpecified = true;
funcLoc.Stage.StageID = “OPERATIONAL”; ;

funcLoc.FunctionaLocExt[0].action = AxdEnum_AxdEntityAction.update;
funcLoc.FunctionaLocExt[0].actionSpecified = true;

funcLoc.FunctionaLocExt[0].DirPartyTable[0].action = AxdEnum_AxdEntityAction.update;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].actionSpecified = true;

funcLoc.FunctionaLocExt[0].DirPartyTable[0].AddressView[0].StreetNumber = “10”;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].AddressView[0].Roles = “HOME”;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].AddressView[0].Street = “street updated MI “;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].AddressView[0].action = AxdEnum_AxdEntityAction.update;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].AddressView[0].actionSpecified = true;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].AddressView[0].updateMode = AxdEnum_ValidTimeStateUpdate.Correction;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].AddressView[0].updateModeSpecified = true;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].ContactView[0].Locator = “+61 (0) 12 345 9999”;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].ContactView[0].Roles = “Home”;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].ContactView[0].Type = AxdEnum_LogisticsElectronicAddressMethodType.Phone;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].ContactView[0].action = AxdEnum_AxdEntityAction.update;
funcLoc.FunctionaLocExt[0].DirPartyTable[0].ContactView[0].actionSpecified = true;

client.update(context, keys, funcLocDoc);
Console.Write(“Worked”);
Console.ReadLine();
}

}
}
catch (Exception e)
{
string message = e.Message;
if (e.InnerException != null)
{
message += ” : ” + e.InnerException.Message;
Console.WriteLine(message);
Console.ReadLine();
}
}
finally
{
if (client != null)
{
if (client.State == System.ServiceModel.CommunicationState.Faulted)
client.Abort();
else if (client.State != System.ServiceModel.CommunicationState.Closed)
client.Close();
}
}
}

 

Update using findkeys:

class Program
{
static void Main(string[] args)
{
Program mFLoc = new Program();
//msp.createSP();
//mFLoc.updateSP();
}

public void updateSP()
{
//int spId;
EAMTerminalGroupLocationServiceClient client = null;
try
{
//Create the client object and context
//EAMServiceProviderServiceClient client = new EAMServiceProviderServiceClient();

//Call context
CallContext context = new CallContext();
context.Company = “EAM”;
context.Language = “en-US”;

QueryCriteria criteria = new QueryCriteria()
{
CriteriaElement = new CriteriaElement[]
{
new CriteriaElement()
{
DataSourceName = “FunctionalLoc”,
FieldName = “FunctionalLocationID”,
Operator = Operator.Equal,
Value1 = “6555”
}
}
};

client = new EAMTerminalGroupLocationServiceClient();
client.Open();
EntityKey[] keys = client.findKeys(context, criteria);
if (keys != null && keys.Length > 0)
{
AxdEAMTerminalGroupLocation axdEAMTGL = client.read(context, keys);

if (axdEAMTGL != null && axdEAMTGL.FunctionalLoc != null)
{
AxdEntity_FunctionalLoc funcLoc = axdEAMTGL.FunctionalLoc.First();

funcLoc.FunctionalLocationType = “2”;
funcLoc.Name = “myname”;
funcLoc.ParentFunctionalLocation = “242”;
funcLoc.action = AxdEnum_AxdEntityAction.update;
funcLoc.actionSpecified = true;
funcLoc.FunctionalExt = null;
//funcLoc.ObjectTable = null;

AxdEntityKey_MROParmStageFunctionalLocation funcLocStg = new AxdEntityKey_MROParmStageFunctionalLocation();

funcLocStg.StageID = “operational”;
funcLocStg.InstanceRelationType = 105527;
funcLoc.Stage = funcLocStg;

funcLoc.ObjectTable[0].action = AxdEnum_AxdEntityAction.update;
funcLoc.ObjectTable[0].actionSpecified = true;

funcLoc.ObjectTable[0].ObjectID = “179”;
funcLoc.ObjectTable[0].Name = “i13311”;
funcLoc.ObjectTable[0].action = AxdEnum_AxdEntityAction.update;
funcLoc.ObjectTable[0].actionSpecified = true;

//funcLoc.ObjectTable[0].ObjectSpec = null;
funcLoc.ObjectTable[0].FuncLocObject = null;

funcLoc.ObjectTable[0].ObjectSpec[0].SpecificationTypeId = “POSITION_ID”;
funcLoc.ObjectTable[0].ObjectSpec[0].ValueString = “4”;//123
funcLoc.ObjectTable[0].ObjectSpec[0].action = AxdEnum_AxdEntityAction.update;
funcLoc.ObjectTable[0].ObjectSpec[0].actionSpecified = true;

client.update(context, keys, axdEAMTGL);
}
}
}

catch (Exception e)
{
string message = e.Message;
if (e.InnerException != null)
{
message += ” : ” + e.InnerException.Message;
Console.WriteLine(message);
Console.ReadLine();
}
}
finally
{
if (client != null)
{
if (client.State == System.ServiceModel.CommunicationState.Faulted)
client.Abort();
else if (client.State != System.ServiceModel.CommunicationState.Closed)
client.Close();
}
}
}
}

Create and update multiple record in a child:

class Program
{
static void Main(string[] args)
{
//Working One
//Create the client object and context
EAMTerminalGroupLocationServiceClient client = new EAMTerminalGroupLocationServiceClient();
List<String> objectIdList = new List<String> { “173”, “174” };

// Create an instance of the document class.
AxdEAMTerminalGroupLocation TGLinsert = new AxdEAMTerminalGroupLocation();

CallContext context = new CallContext();
context.Company = “EAM”;

// Create instances of the entities that are used in the service and
// set the needed fields on those entities.
AxdEntity_FunctionalLoc funcLocIns = new AxdEntity_FunctionalLoc();

funcLocIns.FunctionalLocationID = “228”;
funcLocIns.Name = “Testing_FL”;
funcLocIns.FunctionalLocationType = “3”;
funcLocIns.ParentFunctionalLocation = “Test”;

List<AxdEntity_ObjectTable> objList = new List<AxdEntity_ObjectTable>();

foreach (string id in objectIdList)
{
AxdEntity_ObjectTable objectTableIns = new AxdEntity_ObjectTable();

objectTableIns.ObjectID = id;
objectTableIns.ObjectType = “112”;
objectTableIns.Name = “Test_Object”;
objList.Add(objectTableIns);

AxdEntity_FuncLocObject funcLocObj = new AxdEntity_FuncLocObject();

objectTableIns.FuncLocObject = new AxdEntity_FuncLocObject[1] { funcLocObj };
objectTableIns.ObjectSpec = null;

funcLocIns.ObjectTable = objList.ToArray();
}

TGLinsert.FunctionalLoc = new AxdEntity_FunctionalLoc[1] { funcLocIns };

try
{
EntityKey[] entityKeys = client.create(context, TGLinsert);

// The create method returns an EntityKey which contains the ID of the sales order.
//EntityKey returnedFloc = (EntityKey)returnFloc.GetValue(0);
Console.WriteLine(“the TGL has been created successfully”);
//Console.ReadLine();

AxdEAMTerminalGroupLocation TGLUpd = client.read(context, entityKeys);

AxdEntity_FunctionalLoc funcLocUpd = TGLUpd.FunctionalLoc.First();

funcLocUpd.FunctionalLocationType = “3”;
funcLocUpd.Name = “Test_TGL”;
funcLocUpd.Stage.StageID = “Operational”;
funcLocUpd.action = AxdEnum_AxdEntityAction.update;
funcLocUpd.actionSpecified = true;
funcLocUpd.FunctionalExt = null;

AxdEntity_ObjectTable[] objUpdList = funcLocUpd.ObjectTable;

foreach (AxdEntity_ObjectTable objUpd in objUpdList)
{
objUpd.FuncLocObject = null;
objUpd.Name = “Test123”;
objUpd.Stage.StageID = “15”;
objUpd.action = AxdEnum_AxdEntityAction.update;
objUpd.actionSpecified = true;

AxdEntity_ObjectSpec[] objSpecList = objUpd.ObjectSpec;

foreach (AxdEntity_ObjectSpec objSpecUpd in objSpecList)
{
if (objSpecUpd.SpecificationTypeId == “OBJ_CLASSIFICATION”)
{
objSpecUpd.ValueString = “Notional”;
}
else if (objSpecUpd.SpecificationTypeId == “UPDATE_SOURCE”)
{
objSpecUpd.ValueString = “MYKI”;
}
else
{
objSpecUpd.ValueString = “Terminal”;
}
objSpecUpd.action = AxdEnum_AxdEntityAction.update;
objSpecUpd.actionSpecified = true;
}
}
client.update(context, entityKeys, TGLUpd);

Console.WriteLine(“the TGL has been updated successfully”);
Console.ReadLine();
}

catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}
}
}

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s