Disclaimer: This sample is not a production ready solution. As
described below the user credentials will be passed in plain text which is not
ideal in a production environment. To prevent this from occurring it
would be recommended to incorporate SSL with this solution.
1.
Create inbound HTTP port.
a.
Navigate to System
administration->Setup->Services and Application Integration
Framework->Inbound ports.
Basic settings:
Service operations:
1.
Activate the new inbound port.
2.
We need to configure the client
configuration. In order to do this you need to select the ‘Configure’
button. Note: Do not select the ‘Configure AOS’ button.
3.
You should see a dialog with a
warning. Just click yes to continue loading the configuration file.
4.
Locate the Bindings section under the
Configuration frame and select ‘New Binding Configuration’ from the Bindings
frame.
5.
Select ‘basicHttpBinding’ and click OK.
6.
In the ‘Name’ field enter
‘basicHttpBindingWithBasicAuth’.
1.
Click the ‘Security’ tab and set the
attributes as shown below.
1.
Locate the ‘reqReplyEndpoint’ in the
Configuration frame, and highlight it.
2.
Change the BindingConfiguration
attribute for the endpoint from ‘basicHttpBindingWithWindowsAuth’ to
‘basicHttpBindingWithBasicAuth’.
1.
Save the configuration file and close
the WCF configuration editor.
2.
Activate the SalesOrderHTTPService
port.
3.
Open IIS manager and navigate to the
MicrosoftDynamicsAXAif60 virtual directory. Highlight it, and from the
main frame open ‘Authentication’ from the IIS group.
4.
Enable Basic Authentication. Your
settings should look like that below.
1.
Close IIS manager and complete an
iisreset from a command prompt.
2.
Open Visual Studio.
3.
Select File->New->Project.
From the New Project dialog select Windows Forms Application. Enter a
name for the project (e.g. SalesOrderTest). Click OK.
1.
Once the project opens drag a button
from the toolbox onto the form.
1.
Add the Sales Order Service reference
to the project. Note: You can pull the address from the
‘Inbound ports’ form within Dynamics Ax.
Important: You will be asked for credentials in order to access the
service and metadata. I entered my administrator account and password
until the RoutingService showed in the Services frame below, then cancelled all
remaining authentication dialogs. This will only work if you have Windows
and Basic authentication enabled on your IIS box for the AIF virtual directory.
1.
Close IIS manager. Open a command
prompt and complete an iisreset.
2.
Open Visual Studio and open your
project back up.
3.
Double-click the Button on the form to
open the code window and create a new button_click event.
4.
Add a ‘using’ statement for the sales
order web service.
1.
Within the newly created button click
event paste the following code.
SalesOrderServiceClient proxy = new SalesOrderServiceClient();
proxy.ChannelFactory.Credentials.UserName.UserName = @"domain\user";
proxy.ChannelFactory.Credentials.UserName.Password = @"password";
CallContext context = new CallContext();
context.Company = "ceu";
AxdSalesOrder salesOrder = new AxdSalesOrder();
AxdEntity_SalesTable[] salesTables = new AxdEntity_SalesTable[1];
AxdEntity_SalesTable salesTable = new AxdEntity_SalesTable();
salesTable.CurrencyCode = "USD";
salesTable.CustAccount = "1103";
salesTable.ReceiptDateRequested =
Convert.ToDateTime("2/1/2012");
salesTable.Payment = "N060";
salesTable.PurchOrderFormNum = "PO113";
#region Financial Dimensions
AxdType_DimensionAttributeValue dimBusinessUnit = new
AxdType_DimensionAttributeValue();
dimBusinessUnit.Name = "BusinessUnit";
dimBusinessUnit.Value = "20";
AxdType_DimensionAttributeValue dimCustomerGroup = new
AxdType_DimensionAttributeValue();
dimCustomerGroup.Name = "CustomerGroup";
dimCustomerGroup.Value = "10";
AxdType_DimensionAttributeValue dimDepartment = new AxdType_DimensionAttributeValue();
dimDepartment.Name = "Department";
dimDepartment.Value = "500";
AxdType_DimensionAttributeValueSet valueSet = new
AxdType_DimensionAttributeValueSet();
valueSet.Values = new AxdType_DimensionAttributeValue[3] { dimBusinessUnit,
dimCustomerGroup, dimDepartment };
salesTable.DefaultDimension
= valueSet;
#endregion
AxdEntity_SalesLine salesLine = new AxdEntity_SalesLine();
salesLine.ItemId = "1000";
salesLine.SalesQty = 1;
salesLine.SalesUnit = "ea";
AxdEntity_SalesLine salesLine2 = new AxdEntity_SalesLine();
salesLine2.ItemId = "1000";
salesLine2.SalesQty = 55;
salesLine2.SalesUnit = "ea";
AxdEntity_SalesLine salesLine3 = new AxdEntity_SalesLine();
salesLine3.ItemId = "10004";
salesLine3.SalesQty = 21;
salesLine3.SalesUnit = "Pcs";
AxdEntity_InventDim inventDim = new AxdEntity_InventDim();
inventDim.InventSiteId = "1";
salesLine3.InventDim = new AxdEntity_InventDim[1] { inventDim };
salesTable.SalesLine = new AxdEntity_SalesLine[3] { salesLine, salesLine2,
salesLine3 };
salesOrder.SalesTable = new AxdEntity_SalesTable[1] { salesTable };
try
{
proxy.create(context, salesOrder);
MessageBox.Show("Worked");
}
catch (Exception ex)
{
throw ex;
}
1.
Open IIS manager and navigate to the
MicrosoftDynamicsAXAif60 virtual directory. Highlight it, and from the
main frame open ‘Authentication’ from the IIS group.
2.
Disable Windows Authentication.
Your settings should look like that below.
1.
Close IIS manager and complete an
iisreset from a command prompt.
2.
Build and test the program.
Note: The data presented in the sample above may not coincide
with your existing database. You may have to update the code to validate
against your AX setup. If you do not update the sample code you are
likely to get a validation error returned from the server.
Happy DAXing.. :)
Source : MSDN Blog