How to display ax 2009 Integration Read method Data in Web Services(throu BC)

Hi all,

I need to Display Ax 2009 Integration Read method readed data at time of Run the We service.

Regards,

Pavan.

HI Pavan,

you can try this.

[WebMethod]

public List ReadMethod()

{

Axapta ax;

AxaptaRecord axRecord;

string tableName = “LogisticsAddressState”;

// The LogisticsAddressState field names for calls to

// the AxRecord.get_field method.

string strNameField = “NAME”;

// The output variables for calls to the

// AxRecord.get_Field method.

object fieldName;

try

{

// Login to Microsoft Dynamics AX.

ax = new Axapta();

ax.Logon(null, null, null, null);

List li = new List();

// Create a query using the AxaptaRecord class

// for the StateAddress table.

using (axRecord = ax.CreateAxaptaRecord(tableName))

{

// Execute the query on the table.

axRecord.ExecuteStmt(“select * from %1”);

// Loop through the set of retrieved records.

while (axRecord.Found)

{

// Retrieve the record data for the specified fields.

fieldName = axRecord.get_Field(strNameField);

li.add(fieldName);

// Advance to the next row.

axRecord.Next();

}

}

return li;

}

catch (Exception e)

{

Console.WriteLine(“Error encountered: {0}”, e.Message);

// Take other error action as needed.

}

}

Pavan, could you please spend a few minutes explaining what exactly you’re trying to do and what’s the problem you need help with?

HI Pavan, you can try this also.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Services;

using Microsoft.Dynamics.BusinessConnectorNet;

namespace WebApplication3

{

///

/// Summary description for WebService1

///

[WebService(Namespace = “http://tempuri.org/”)]

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.ComponentModel.ToolboxItem(false)]

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

// [System.Web.Script.Services.ScriptService]

public class WebService1 : System.Web.Services.WebService

{

[WebMethod]

public List ReadMethod()

{

Axapta ax;

AxaptaRecord axRecord;

string tableName = “CustTable”;

object fieldName;

// Login to Microsoft Dynamics AX.

ax = new Axapta();

ax.Logon(“USMF”, “en-us”, “”, “”);

List li = new List();

using (axRecord = ax.CreateAxaptaRecord(tableName))

{

axRecord.ExecuteStmt(“select * from %1”);

while (axRecord.Found)

{

fieldName = axRecord.get_Field(“AccountNum”);

li.Add(fieldName.ToString());

axRecord.Next();

}

}

return li;

}

}

}

In the above code i am returning the result using List

.

[WebMethod]

public List ReadMethod()

{

Axapta ax;

AxaptaRecord axRecord;

string tableName = “CustTable”;

object fieldName;

// Login to Microsoft Dynamics AX.

ax = new Axapta();

ax.Logon(“USMF”, “en-us”, “”, “”);

List li = new List();

using (axRecord = ax.CreateAxaptaRecord(tableName))

{

axRecord.ExecuteStmt(“select * from %1”);

while (axRecord.Found)

{

fieldName = axRecord.get_Field(“AccountNum”);

li.Add(fieldName.ToString());

axRecord.Next();

}

}

return li;

}

Hi Martin,

Thanks for reply .My problem is solved as per the Raman Reply Message.

Regards,

Pavan.

Hi Raman,

Thanks for your Reply my problem is solved.

Regards,

Pavan.

In that case, please mark Raman’s answer as the verified solution.