Dynamics AX 2012 Custom AIF document service read method returns empty array - dynamics-ax-2012

After following the basic steps creating a custom document service with the AIF Document Service Wizard (http://technet.microsoft.com/en-us/library/aa856656.aspx). I tested it out with the WCF Test Client, but the read() method returns nothing. The Response entity returns an empty array.
I'm simply trying to retrieve rows from a table. I think I need to specify a value for the EntityKeyList, but I'm not sure what that would be. Perhaps Read is the wrong method.

I deleted the generated objects, and re-ran the AIF Document Service Wizard on my Query this time including all the CRUD methods available. Then with WCF Test Client I tried the find method. I expanded the QueryCriteria and provided a CriteriaElement of null then Invoked the request, which returned all the rows from my table!

Related

Understanding of OData services

This is a question to improve my understanding about OData and the process of OData services. I'm not sure about the process when an OData request is sent to the server from my Fiori app. The app is added to our Fiori Launchpad. When the user wants to create a new target group in the UI, a create request is sent. What happens then in detail? What I thought so far:
OData service checks the data
If the data is valid, a new entry in the database is created (HTTP POST)
If the data is not valid, the OData service sends an error
I'm not sure about what information is delivered by the OData service and what information is delivered directly from the database? Does the OData service work like a adjustor which transfers the messages sent from the database to the application?
I hope you can understand what I'm trying to figure out. Thank you for your time.
it depends how your backend-methods are implemented. Every Entityset usually has one of these Methods:
Get Entity
Get EntitySet
Create
Update
Delete
There are some more I guess, but these are mostly used by developers. You can redefine every single method and implement your own Business Logic in there.
So, let's assume you want to send data from the Frontend to your service and insert the data into a table inside your database. You have to redefine the create method of your entity and implement own logic. This could contain an insert into a database-table. You have to consider, that your oData Service will throw an Error if the types which are sent from the frontend do not match the Entity-Types (i.e. a String into an edm.Time type).
Here you can find all EDM.Types oData could consume and the correct mapping of the types:
https://help.sap.com/saphelp_gateway20sp12/helpdata/en/76/4a837928fa4751ab6e0a50a2a4a56b/frameset.htm
Hope this helps :)

AX2012 Is it possible to access the Call Context from inside a Custom Service Operation?

I have a Custom Inbound AIF Service in Dynamics AX 2012. I'd like to access to the MessageID inside my Custom Service Operation. Is it possible to access the Call Context object from inside my Custom Service Operation?
Out of the box, this isn't possible.
You can modify the AifDispatcher.callServiceMethod method to achieve this though. For example by saving it to a table and passing the RecId to your service class. Or passing the (a copy of) context as another parameter. Both options aren't very clean though.

Save query result from GET method for future reference

I want to implement a query on my web page that gets results from another web service and displays them to the user. For this I ofcourse send the request as GET method from the web page. Server side, I process the request, get results from that web service and return them back to user.
However, I also want to save the results for future refernce. Something like history of queries. For this I will store the results in a database.
Now, the question is since I am upating my database everytime a query is made, should I be using POST method on the web page or GET would do? Does HTTP explicitly say anything for this scenario?
HTTP itself doesn't say you have to use POST -- the technology will work just fine if you're sending your data on queryparams.
But current convention says that you should use POST, specifically when using API services under a RESTful model. If you are passing data (even on the query params) that is creating a new record, it should use the POST verb. Updating it should use PUT.
It's going to get down to what your audience expects. If it's just an internal resource, go for it with GET. If you expect to open this up as a public service, use POST.

hiding method from certain layers in project

I was looking through an old project and wanted to see if anyone had a suggestion on how to hide certain methods from being called by various layers. This was a 3 tier project, webapplication -> web service -> database
In the application there is a User object for example. When a User was being updated, the webapplication would create a User object and pass it to the webservice. The webservice would use the DataAccessLayer to save the User object to the database. After looking at this I was wondering if instead I should have made a Save method in the User class. This way the service and simply call the Save on the User object which would trigger the db update.
However doing it this way would expose the Save to be called from the webapplication as well, correct? Since the webapplication also has access to the same User object.
Is there anyway around this, or is it better to avoid this altogether?
There is a separation of concerns by keepeing the User object as object that only holds data with no logic in it. you better keep it separated for the following reasons:
As you stated, it is a bad practice since the Save' functionality will be exposed to other places/classes where it is irrelevant for them (This is an important for programming generally).
Modifying the service layer - I guess you are using WCF web service as you can transfer a .NET object (c#/VB) to the service via SOAP. If you put the saving logic in the 'User' object, you can't replace it another webservice that receives a simple textual data structures like JSON or XML or simply doesn't support .NET objects.
Modifying the data storage layer - If you want, for example, to store the data inside a different place like other database such as MongoDB, RavenDB, Redis or what ever you want, you will have to reimplement each class that responsible for updating the data. This is also relevant for Unit Testing and Mocking, making them more complicated to interrogate.

Fails to generate Insert,Update,Delete methods on the client-side in ria services

I've added insert/update methods to the domain service class.
They start with the appropriate words Insert/Update and are marked with the correspondent attributes.
Yet, they fail to get generated at the client-side so they are unavailable
from the domain context.
Is it a bug, a known by-design feature, or am I missing something?
Thanks in advance
These methods are not exposed on the client side. They are used when SubmitChanges() is called to insert, update and delete entities in the entity collection. You can add and update entities in the entity collection and they will be marked as changed or added. Then when SubmitChanges() is called, your server side code will be used.
I found this article helpful:
How SubmitChanges works in .NET RIA Servies

Resources