Connect a mobile device like a smartphone with Dynamics AX using web services. Microsoft Dynamics AX 2009 with AIF Webservices installed and Visual Studio for Smart Device development.
Deploy AIF Service
- Go to Basic → Setup → Application Integration Framework → Services
- Select Refresh button to update service list
- Enable CustCustomerService
- Generate the webservice
- To verify your service is working open the IIS manager
- Go to → Sites → Default Web Site → MicrosoftDynamicsAxAif50 → Content View
- Right Click on CustomerSerivce.svc and Browser
- You should see a web page with a link to a WSDL file
- Follow the link an you should see an XML document containing the service contract
Mobile Device Project
- Open Visual Studio and Create a new Solution
- Add a new Smart Device Project
- Go to References and add a new service reference
- Provide the URL of your Dynamics AX CustomerService
- Open Form1.cs file
- Add a text field (Name: textBoxAccountNum),
a button (Name: buttonLookup)
and a label (Name: labelName) to your form - Double Click on the button and implement the service call:
private void buttonLookup_Click(object sender, EventArgs e) { System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(); credentials.Domain = "YOUR_DOMAIN_NAME"; credentials.UserName = "YOUR_USER_NAME"; credentials.Password = "YOUR_USER_PASSWORD"; QueryCriteria query = new QueryCriteria(); query.CriteriaElement = new CriteriaElement[1]; query.CriteriaElement[0] = new CriteriaElement(); query.CriteriaElement[0].DataSourceName = "CustTable"; query.CriteriaElement[0].FieldName = "AccountNum"; query.CriteriaElement[0].Operator = Operator.Equal; query.CriteriaElement[0].Value1 = textBoxAccountNum.Text; CustomerService service = new CustomerService(); service.Credentials = credentials; try { AxdCustomer customer = service.find(query); if (customer != null && customer.CustTable != null && customer.CustTable.Length > 0) { labelName.Text = customer.CustTable[0].Name; } } catch (Exception ex) { MessageBox.Show("Service failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1); } }
You application should look like that:
No comments:
Post a Comment