Hi
There!
As
promised, in this post we’ll see how to create a simple demo service using AX
2012. Please refer to my last post about AX 2012 Service Documents Types and A Simple Introduction to AX 2012 Services Architecture to get a more
detailed explanation to AX 2012 Services.
Also,
I would like to point out that AX 2012 services are hosted on the AOS, and that
both internal and external applications will be authenticated through the AOS. With this being said, the following example
will be an internal application that will get the customer name from AX
services.
If I wanted to have an external application executing the same operation
I would have to host the services in IIS. For more information on services
please refer to this white paper.
Further,
when working with AX 2012 WCF services, we will
have to dive into data contracts. In this sample service will use a DataContractAttribute. The string DataContractAttribute indicates that this class is a Data Contract. The square brackets [] indicate that this string is an attribute. We are also going
to be using Data Members, which would
help us define the default values for our data
contracts.
If
you are new to this, don’t worry, you can find a lot of information about Data Contracts and Data Members out there.
Another
concept that we’ll be exposed on this example is the SysEntryPointAttribute, which helps with
authorization checks and how they are performed for a method that is called on
the server. Further, this is a very important class when working with Services
in AX 2012 as we have to use it for
all service operations.
So,
let’s start working on our simple service. (Please note that I’m working on a
project that involves a lot more detail. When done I will share it with you, so
we can understand many other concepts about AX 2012 that won’t be covered in
this post)
1. Open the AOT.
2. Create a new
class.
3. Enhance the class
by adding the [DataContractAttribute]
attribute.
4. Create a new
method.
5. Enhance the class
by adding the [DataMemberAttribute] attribute.
6. Create another
class.
7. Create a method
that instantiates the class created in Step 2.
8. Enhance the class
that uses the [SysEntryPointAttribute]
attribute.
9. Right-click the
Services node in the AOT and select New Service.
10. Enter a name into
the Name property.
11. Set the Class
property to the class created in Step 6.
12. Expand the new
service node.
13. Right-click the
Operations node and select Add Operations.
14. Right-click the
Services Group node in the AOT and select New Service Group.
15. Enter a name into
the Name property.
16. Drag-and-drop the
service created in step 9 under the Service Group node.
17. Right-click the
service group and select Deploy service group.
Ok, so at this point we should have our new AX 2012 service already
working. The next step is to learn how to use this service from Visual Studio
2010. Please refer to this article if
you are new to adding services references to Visual Studio. It will help you
understand the underlying concepts of this operation.
1. Select File > New > Project to create a new project of type Console Application.
2. Enter a name into
the Name field and then click OK.
3. Right-click the
Service reference node under the project.
4. Select Add Service
Reference.
5. Enter the address
and then click GO.
6. Select the service
and then click OK.
NOTE: The address format in step 5 is http://<machinename>:8101/DynamicsAx/Services/Xpp.
7. Invoke the service
from the client.
8. Click F5 to run
the service.
As
you can see, when you run the service, the first customer name that are available
in your system will be presented as an output. There is a lot more to services and you can
start learning more about it by going to partner source and/or downloading the
new AX 2012 white papers focusing on services.
I
will be posting a lot more on this later soon, so keep reading my blog as there
is a lot more to come.
Take
Care and have a great weekend!
Nice post!! Thanks a lot for the info
ReplyDeleteYou are very welcome!
DeleteThanks for reading my blog
HI John,
ReplyDeleteI need your help ,a vendor will provide me a webservice which will consume by me on ax side .Its a update function ,i will first retrieve the values from ax side pass those values using their webservice .Please help me on this .Kindly mail me on jagannath555@gmail.com
Hi John,
ReplyDeleteI am quiet new to the AX world. I have a job in hand to integrate sales order from Dynamic CRM 2011 to AX 2012. Can you give me your valuable inputs please like where should i start from or any steps that is should follow.
Thanks Mate for sharing your knowledge.
Cheers
Dawson
dawson@geidi.com
Hey Dawson,
DeleteIt is fairly simple. AX 2012 has the capability to integrate with CRM.
Check the following links for instructions:
http://blogs.msdn.com/b/dax/archive/2011/11/11/connecting-microsoft-dynamics-ax-2012-with-microsoft-dynamics-crm.aspx
http://dynamics-ax.blogspot.com/2011/02/out-of-box-connector-for-dynamics-ax.html
https://community.dynamics.com/product/ax/axtechnical/b/axresources/archive/2012/07/02/resource-page-for-crm-connector-in-microsoft-dynamics-ax-2012.aspx
I hope this helps
Hey John,
DeleteI have already tried the connector. It has plenty of limitations and restrictions in CRM after integration.
Lately i have been checking out webservices that are availaible in AX through AIF. I did notice there is CustFreeTextInvoice service availaible but i am not sure how can i use it C#. You can please throw some light on it.
I have tried doing it looking at this link http://msdn.microsoft.com/EN-US/library/hh496418.aspx
but it was not much of help.
For now i am only looking out to move invoices from CRM to AX as free text invoice without the using Excel Addin.
Hi,
DeleteBy the way my name is not John. John is the name that said the quote i have in my blog. My name is Eduardo :)
Anyway, for that specific requirement, look at the course 80416 is partner source or customer source (https://mbs.microsoft.com/partnersource/communities/training/trainingmaterials/student). There is an example there to get what you need.
I hope this helps
Sorry Eduardo,
DeleteFor some reasons I thought your name is John.
I do have access to partner source but dont have access to that particular course.
So is it anywhere possible for you to copy paste the example from there to here or email me Please.
Thanks