Monday, March 21, 2011

Consume AIF Inventory On Hand web service in AX PART 2 - WSDL request

This is the second part of the consuming AX 2009 AIF On Hand Inventory web service via C#. The first part was consuming an AIF web service using SOAP. This one is using WSDL

DocumentContext context;
WebReference.InventoryOnhandService ws;

// Populate Document Context
context = new DocumentContext();
context.SourceEndpoint = "DAT";
context.DestinationEndpoint = "DAT";
context.SourceEndpointUser = Environment.ExpandEnvironmentVariables("DOMAIN\\WEBSERVICEUSER");
// Invoke the Web Service
ws = new WebReference.InventoryOnhandService();
ws.Credentials = new NetworkCredential("WEBSERVICEUSER", "PASSWORD", "DOMAIN"); // System.Net.CredentialCache.DefaultCredentials; // Use the current user to authenticate in IIS
ws.Url = "http://99.999.99.99/inventoryonhandservice.asmx";

// Create new Guid
context.MessageId = Guid.NewGuid().ToString();

//Create Query Criteria
CriteriaElement myCriteria = new CriteriaElement();
myCriteria.FieldName = "ItemId";
myCriteria.Operator = Operator.Equal;
myCriteria.Value1 = "AX_ITEM";
myCriteria.DataSourceName = "InventSum";

QueryCriteria myQueryCriteria = new QueryCriteria();
myQueryCriteria.CriteriaElement = new CriteriaElement[1];
myQueryCriteria.CriteriaElement[0] = myCriteria;

// Call find list
WebReference.AxdInventoryOnhand ioh = ws.findListInventoryOnhand(context, myQueryCriteria);

// Display the result

No comments:

Post a Comment