Translate

Wednesday, October 12, 2011

Consuming Web Services in AX 2012

Consuming Web Services in AX2012

Consuming a web service is always very exciting in any technology. I wanted to explore the same in AX 2012. You can download the official document regarding same using the below link:
Source Link: Here



I tried to consume the web service mentioned in the downloaded documents and made some modifications as well to suit my requirements and it worked pretty well. But it was all like working as per the document and being happy on something which was already accomplished. I wanted to consume another web service. So, I searched the internet a bit and found out a web service to check the weather conditions of a city and here are the steps to get this done:

1. Create a new project:



 2. Add the service reference by right clicking the project name and click on “Add service reference”. Enter the URL of the web service in the address box and click ‘GO’ to validate the web service. Change the namespace and click ‘OK’ button:



3. Add the project to the AOT:


4. Set the deployment properties:


5. Restart the Microsoft Dynamics AX client. This is an important step.

6. Write a job in X++ in AX 2012 to access the web service and output the result set:


       Below is the output of the job:


7. Go to AX 2012 and verify the changes in service reference


14 comments:

  1. Thanks for this post, it has been very useful for me.

    ReplyDelete
  2. Hi Mukesh,

    Its a nice one, i was trying the same to consume webservices works and i have created the VS2012 project all the steps until creation of the Job.
    When i am initialising the webservice iam not getting compiled that and says varialble "WeatherConditions" not declared. Could you please suggest me if something i am missing.

    Currently i am working on webservice to expose to outside of AX and wanted to test it using SOAP tool, t would be great if you can share points which are mandatary.

    Thanks in Adv.
    Regards..Satish

    ReplyDelete
    Replies
    1. While adding Service Reference, what namespace you've provided?
      It should be "WeatherConditions" while adding, see above screenshot in step 2.

      Delete
    2. Hi Mukesh,

      Thanks for the spontaneous reply.

      I have given the samename but still not recognised.

      I need one more help i need i have activated a webservice for Products(standard - EcoResProductService) and trying to test it using SOAP tool, but i am getting many errors like "Invalid schema and value cannot be null".
      Any suggestions please.

      Thanks in Advance.

      Regards

      Delete
    3. Hi, U can check the schema file (XSD) for the service. Fields which are declared as "minOccurs = 1" must be passed. Else during XML validation it will get failed.

      U can check same in Inbound port > Data policies > View schema.

      Delete
  3. Hi Mukesh,

    I am getting the following error.

    "Assembly containing type Weather.WeatherConditionsServiceReference.GlobalWeatherSoapClient is not referenced."

    Thanks.

    ReplyDelete
    Replies
    1. Hi,

      Refer the names u provided for .Net project. The above statement must be like
      <>.<>.<>

      Everytime u will put a dot between words, u will get further related methods in lookup. Just follow same.

      Happy DAXing :)

      Delete
  4. Hi,

    Refer the names u provided for .Net project. The above statement must be like
    "ProjectNameInAOT"."Namespace"."GlobalWeatherSoapClient"

    Everytime u will put a dot between words, u will get further related methods in lookup. Just follow same.

    Happy DAXing :)

    ReplyDelete
  5. Hi Mukhesh...

    Need some suggestion..

    I need a create a service reference which needs to import the data from iphone application. An iphone application has been created of type like pos terminal , i need to take data from iphone application and store it in Ax data base and vice versa....

    Your reply is highly appreciated here...

    Thank you,
    Kumar.

    ReplyDelete
    Replies
    1. U can create a Web service in IPhone app by using link below:
      http://blogs.oreilly.com/iphone/2008/09/creating-an-iphone-based-web-s.html

      Once web service is created and hosted, u can consume same as mentioned in the above article.

      Delete
  6. Hi ,

    I am getting the following error.

    "XmlNode object not initialized."

    ReplyDelete
    Replies
    1. Hi, Check your location, I hope u wud not be getting any string in weatherInformation object.

      Delete
  7. hi,
    firstly thanks for your good post.

    but i have a problem i want to add Web Reference to VS then i want to use this refences in AX. adding web reference and deploy to aot is easy but i can't use web reference with X++. do u know something about using added web reference ?
    Thanks

    ReplyDelete
  8. Hi Mukesh, I done all the above steps, geeting error when AX job calling getweather method

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (407) Proxy Authentication Required

    ReplyDelete