I have a Web Service for my ASP.NET MVC 3 app which creates a new Sales Order in AX. In AX I have created an OnlineOrder class which has 1 method for now. It is to generate a Sales Reference. Below is the code in my web service:
public AxaptaObject order;
public void CreateOrder()
{
AxaptaStart();
order = Axapta.CreateAxaptaObject("OnlineOrder");
AxaptaStop();
}
public string GetSalesRef(string username, string delivery, string reference)
{
AxaptaStart();
string number = order.Call("orderCreate", username, delivery, reference).ToString();
AxaptaStop();
return number;
}
Then in my Controller I call these methods:
client.CreateOrder();
string number = client.GetSalesRef(user.Username, order.deliverymethod, order.custorder).ToString();
This doesn’t work and there is no exception info to show, its just a blank message. I believe the order AxaptaObject is not of type OnlineOrder so it can’t call those methods. How would I instantiate the object to use the orderCreate method?
EDIT:
If I do:
public string CreateOrder(string username, string delivery, string reference)
{
AxaptaStart();
order = Axapta.CreateAxaptaObject("OnlineOrder");
string number = order.Call("orderCreate", username, delivery, reference).ToString();
AxaptaStop();
return number;
}
This works, but this isn’t a valid solution as I’d like to add more methods to my OnlineOrder object in the future and I dont want to call them all in 1 method on my web service
This will never work as the
orderobject is sort of closed when you call theAxaptaStopmethod.I will suggest creating a class implementing IDisposable, then call
AxaptaStopin theDisposemethod. TheAxaptaStartcall could go to the constructor. This will allow you to scope the AX context like:The
Disposeis automatically called by the using statement.