1. Create table named SampleAIFTbl with 3 fields (Name, AddressCity, PhoneMobile),
one Class named SampleAIFServiceClass which have one method (getSampleList())
2. In this, I will consume data in to the DAX application with a simple
Example.
3. Create table named SampleRecvTbl with 3 fields (Name, AddressCity,
Email), one Class named SampleAIFRecvClass which have one method setSampleData()
//code
[SysEntryPointAttribute(true)]
public void setSampleData(str name,str addr,str email)
{
sample.Name = name;
sample.AddressCity = addr;
sample.Email = Email;
sample.insert();
}
4. setSampleData() method set field data and insert into table object but it is
called from C# by AIF Web Service through WSDL Port.
5. Create Service from AOT node and select the class created in previous
step in property node, select add operation node, add the method of
class SampleAIFRecvClass and select ok.
6. Create Service Group from AOT node, right click Service Group & select
“New Service Node Reference”, select auto deploy to yes and deploy the
service.
7. Open Company/System administration/Area page/Inbound Ports, select
the created service which is successfully deployed and copy the URI (wait)
8. Open visual studio, create project and select Console Application, once it
opens, open the solution explorer, right click on it & select Add project to AOT.
9.Once project added to AOT, Select Add Service Reference, paste URI and
click Go, give appropriate name so press ok.
10. We can use that service as per requirement, as I am just displaying those
data at console.
Note: Whenever you made modification in AX, deactivate the service, generate CIL
Generation & deploy the service again and in VS, update service reference to avoid errors.
C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SampleRecvConsoleApp.SampleAIFRecvServiceRef;
namespace SampleRecvConsoleApp
{
class Program
{
static void Main(string[] args)
{
string name, address, email;
SampleAIFRecvServiceClient client;
CallContext cc;
Console.WriteLine("Enter name");
name = Console.ReadLine();
Console.WriteLine("Enter address");
address = Console.ReadLine();
Console.WriteLine("Enter Email");
email = Console.ReadLine();
try
{
client = new SampleAIFRecvServiceClient();
cc = new CallContext();
cc.Company = "ussi";
client.setSampleData(cc, name, address, email);
Console.Out.WriteLine("Data is Migrated to AX");
Console.ReadLine();
}
catch (Exception e)
{
Console.Out.WriteLine(e.ToString());
Console.ReadLine();
}
}
}
}
You can code it, debug it, run it, see the output and modified it as you want.
Showing posts with label ERP. Show all posts
Showing posts with label ERP. Show all posts
Monday, 5 January 2015
How to Consume AX code in C# using Custom Service?
1. I will demonstrate now, how to expose AIF Web Service out of the AX.
2. In this, I will expose AX Data out of the application with a simple Example.
3. Create table named SampleAIFTbl with 3 fields (Name, AddressCity,
PhoneMobile), Class named SampleAIFServiceClass which have one
method (getSampleList()).
//code
[SysEntryPointAttribute(true),
AifCollectionTypeAttribute('return', Types::String)]
//return denotes the parameter type and String specifies
//the type of data the collection will hold
public List getSampleList()
{
SampleAIFTbl sampleAIFTbl;
List list = new List(Types::String);
//select all rows
while select * from sampleAIFTbl
{
//add name in the list
list.addEnd(sampleAIFTbl.Name);
//list.addEnd(" ");
}
return list;
}
4. getSampleList() method takes Name field data and insert into List object
of type String and return it C# by AIF Web Service through WSDL Port.
5. Create Service from AOT node and select the class created in previous
step in property node, select add operation node, add the method of
class SampleAIFServiceClass and select ok.
6. Create Service Group from AOT node, right click Service Group & select
“New Service Node Reference”, select auto deploy to yes and deploy the
service.
7. Open Company/System administration/Area page/Inbound Ports, select
the created service which is successfully deployed and copy the URI (wait).
8. Open visual studio, create project and select Console Application, once it
opens, open the solution explorer, right click on it & select Add project to
AOT
9. Once project added to AOT, Select Add Service Reference, paste URI and
click Go, give appropriate name so press ok.
10. We can use that service as per requirement, as I am just displaying those
data at console.
Note: Whenever you made modification in AX, deactivate the service, generate CIL
Generation & deploy the service again and in VS, update service reference to avoid errors.
C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Channels;
using SampleAIFConsole.SampleAIFServiceReference;
namespace SampleAIFConsole
{
class Program
{
static void Main(string[] args)
{
SampleAIFServiceReference.SampleAIFServiceClient client;
try
{
SampleAIFServiceReference.CallContext cc = new
SampleAIFServiceReference.CallContext();
client = new SampleAIFServiceClient();
cc.Company = "ussi";
foreach (string s in client.getSampleList(cc))
{
Console.Out.WriteLine("the values are " + s);
}
Console.ReadLine();
}
catch (Exception e)
{
Console.Out.WriteLine(e.ToString());
Console.ReadLine();
}
}
}
}
You can code it, debug it, run it, see the output and modified it as you want.
2. In this, I will expose AX Data out of the application with a simple Example.
3. Create table named SampleAIFTbl with 3 fields (Name, AddressCity,
PhoneMobile), Class named SampleAIFServiceClass which have one
method (getSampleList()).
//code
[SysEntryPointAttribute(true),
AifCollectionTypeAttribute('return', Types::String)]
//return denotes the parameter type and String specifies
//the type of data the collection will hold
public List getSampleList()
{
SampleAIFTbl sampleAIFTbl;
List list = new List(Types::String);
//select all rows
while select * from sampleAIFTbl
{
//add name in the list
list.addEnd(sampleAIFTbl.Name);
//list.addEnd(" ");
}
return list;
}
4. getSampleList() method takes Name field data and insert into List object
of type String and return it C# by AIF Web Service through WSDL Port.
5. Create Service from AOT node and select the class created in previous
step in property node, select add operation node, add the method of
class SampleAIFServiceClass and select ok.
6. Create Service Group from AOT node, right click Service Group & select
“New Service Node Reference”, select auto deploy to yes and deploy the
service.
7. Open Company/System administration/Area page/Inbound Ports, select
the created service which is successfully deployed and copy the URI (wait).
8. Open visual studio, create project and select Console Application, once it
opens, open the solution explorer, right click on it & select Add project to
AOT
9. Once project added to AOT, Select Add Service Reference, paste URI and
click Go, give appropriate name so press ok.
10. We can use that service as per requirement, as I am just displaying those
data at console.
Note: Whenever you made modification in AX, deactivate the service, generate CIL
Generation & deploy the service again and in VS, update service reference to avoid errors.
C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Channels;
using SampleAIFConsole.SampleAIFServiceReference;
namespace SampleAIFConsole
{
class Program
{
static void Main(string[] args)
{
SampleAIFServiceReference.SampleAIFServiceClient client;
try
{
SampleAIFServiceReference.CallContext cc = new
SampleAIFServiceReference.CallContext();
client = new SampleAIFServiceClient();
cc.Company = "ussi";
foreach (string s in client.getSampleList(cc))
{
Console.Out.WriteLine("the values are " + s);
}
Console.ReadLine();
}
catch (Exception e)
{
Console.Out.WriteLine(e.ToString());
Console.ReadLine();
}
}
}
}
You can code it, debug it, run it, see the output and modified it as you want.
Subscribe to:
Posts (Atom)