Monday, 20 June 2011

How to create & use AX Proxies in Visual Studio

Add to Proxy
  1. In AOT, go to Web->Web Files->Static Files->Proxies.
  2. Right click on Proxies and then click Edit.
  3. Use the Web Application Editor to add definitions for the additional items that you want to include in the proxy. You can use the existing items in the proxy as a template for how to add more items.  
    • To add an Enum, use the following syntax: /enum:EnumName
    • For Classes & methods. /class:ClassName & /method: ClassName.methodName
    • For Table & methods. /table:TableName & method:TableName.methodName
  4. When you are finished making changes, close the Web Application Editor and be sure to save the changes.
Deploy updated Proxy 

  • Go to Microsoft Dynamics AX->Tools-> Development Tools->Web development ->Proxies.
  • Give the following path in the file system directory. C:\inetpub\wwwroot\wss\VirtualDirectories\EP Site Port Number\App_Code\Proxies
  • In the Generate Proxies window, click Generate in the Development Web Site group. After several moments, the proxies will be generated for the Enterprise Portal Web site.

Add Proxies to Visual Studio Project
  •  Open the Visual Studio project for your User Control.
  • In Solution Explorer, right-click the App_Code group. Click Generate Proxies, it create the C# files that provide the interface for the proxy.
  •  To view the C# files generated, expand the Proxies folder in the App_Code group. View the individual files to see details about what each file accesses.
To use Proxies in Visual Studio Project
  • To use the proxy from C# code for the User Controls, you must add the following reference in your code.  using Microsoft.Dynamics.Portal.Application.Proxy;
  • Items in the proxy such as enums can be accessed directly without any additional code. Accessing methods from the proxy requires passing the IAxaptaAdapter object together with the method call. This object is part of the AxSession object. Add the following helper method to the C# file for the User Control in your Visual Studio project to allow for the AxSession object to be retrieved.
    private ISession AxSession 
    AxBaseWebPart webpart = AxBaseWebPart.GetWebpart(this);
    return webpart == null ? null : webpart.Session;
  • When you call the method from the proxy, use this helper method to retrieve the IAxaptaAdapter object. The following example calls the AddNumber method from the Test class.
    protected void Button_AddNo(object sender, EventArgs e)
    string test_result;
    using (IAxaptaAdapter a = this.AxSession.AxaptaAdapter)
    test_result = Test.AddNumber(a, Convert.ToInt16(No1.Text), Convert.ToInt16(No2.Text));
    Total.Text = test_result;

No comments:

Post a Comment