SlideShare une entreprise Scribd logo
1  sur  11
Télécharger pour lire hors ligne
Microsoft Dynamics AX 2012
                              ®




Consuming Web Services
White Paper

Microsoft Dynamics AX 2012 introduces a new model for how to
consume external Web services. This white paper describes how
to reference a Web service and provides example code that
demonstrates how to use the service in X++.




Date: January 2011



Author: Jim Travis, Senior Writer and Nima Kamoosi, Senior
Developer, Application Integration Framework

Send suggestions and comments about this document to
adocs@microsoft.com. Please include the title with your
feedback.
Table of Contents
Introduction ................................................................................................ 3

Audience ..................................................................................................... 3

Prerequisites............................................................................................... 3

Using the Bing API ...................................................................................... 3

Install the Visual Studio tools ..................................................................... 4

Create the service project ........................................................................... 4
    Add the service reference ...................................................................................................... 5
    Add the project to the AOT ..................................................................................................... 6
    Specify the deployment properties .......................................................................................... 6
    Verify the service reference .................................................................................................... 7

Using the Web service ................................................................................. 8
    Creating and configuring a service client object ........................................................................ 8
    Running the job .................................................................................................................... 8




2

CONSUMING WEB SERVICES
Introduction
The previous version of Microsoft Dynamics® AX enabled you to consume external Web services from
X++ code and to consume Web services hosted by Microsoft Dynamics AX from .NET Framework
languages, such as Microsoft Visual C#®. To use a Web service, you added a reference in the Web
references form, as described in the Consume Web Services topic on MSDN
(http://msdn.microsoft.com/en-us/library/cc654149.aspx).
Microsoft Dynamics AX 2012 continues to enable Web services scenarios. However, you now use
Microsoft Visual Studio to create and add a reference to a Web service. This white paper walks you
through creating a reference to the Bing™ API Web service and provides sample code for a job that
consumes the service.


Audience
This white paper is intended for developers who integrate Web services with Microsoft Dynamics AX.


Prerequisites
To benefit from this white paper, you should have experience in the following areas:
   Writing code in .NET Framework languages or X++
   Using Microsoft® Visual Studio®
   Setting up Microsoft Dynamics AX
You must have Microsoft Visual Studio 2010 installed on the computer that is running Microsoft
Dynamics AX 2012.


Using the Bing API
To use the Bing API Web service, you must have the necessary resources and provision your
application by getting an AppID. For more information about the Bing API and to create an AppID, see
the Bing Developer Center (http://www.bing.com/developers).




                                                                                                     3

                                                                             CONSUMING WEB SERVICES
Install the Visual Studio tools
Follow these steps to install the Visual Studio tools for Microsoft Dynamics AX:
1. Run Microsoft Dynamics AX 2012 setup.
2. Under Install, click Microsoft Dynamics AX components.
3. Click Next to go to the Add or modify components page.
4. Under Developer Tools, select Visual Studio Tools.




5. Click Next to step through the remaining setup pages.
6. Click Install to install the tools.
7. Click Finish to close the wizard.
8. Exit setup.


Create the service project
Microsoft Visual Studio 2010 can create a project that Microsoft Dynamics AX can use to build a .NET
assembly (and its configuration file) that exposes types from a Web service reference. Follow these
steps to create a project with the Bing API Web service reference:
1. Open Microsoft Visual Studio 2010.
2. Create a new Visual C# Class Library project. (You can use other .NET Framework languages,
   but this walkthrough uses Visual C#.)
3. For the project name, type “Contoso.ServiceReferences”.




4

CONSUMING WEB SERVICES
4. Click OK to create the project.

Add the service reference
Follow these steps to add a reference to the Bing API Web service to your project:
1. In Solution Explorer, right-click the project name, and then click Add Service Reference.
2. In the Add Service Reference dialog box, type the URL for the Web service in the Address box.
   The URL for the Bing API Web service is:
   http://api.bing.net/search.wsdl?AppID=YourAppId&Version=2.2
   Replace the YourAppId text in the URL with your AppID.
3. Click Go to locate the service.




                                                                                                  5

                                                                             CONSUMING WEB SERVICES
4. Click OK.

Add the project to the AOT
Next, add the project to the Application Object Tree (AOT) in Microsoft Dynamics AX. In Solution
Explorer, right-click the project name, and then click Add Contoso.ServiceReferences to AOT.




Microsoft Dynamics AX imports the project and builds it.

Specify the deployment properties
Next, set the deployment properties in Visual Studio. In the Properties window, specify the following
values for the deployment properties.

6

CONSUMING WEB SERVICES
Name                                Value
Deploy to client                    Yes

Deploy to EP                        No

Deploy to server                    Yes

Deploy to SSRS                      No


Verify the service reference
Follow these steps to verify that the reference to the Bing API Web service appears in the AOT:
1. Restart the Microsoft Dynamics AX client.
2. Open the development workspace.
3. In the AOT, browse to Visual Studio Projects > C Sharp Projects.
4. Verify that Contoso.Servicereferences is listed as a project.




                                                                                                  7

                                                                             CONSUMING WEB SERVICES
Using the Web service
You can now use the Bing API Web service. In this section, you will create a job that performs a Bing
search.

Creating and configuring a service client object
To consume a Web service in Microsoft Dynamics AX 2009, you added a service reference and then
created and used the service client object by using code similar to the following example.
WindowsLiveSearch.MSNSearchPortTypeClient searchService;     // declare the service object
...
searchService = new WindowsLiveSearch.MSNSearchPortTypeClient(); // create the service object
searchResponse = searchService.Search(searchRequest); // use the service to issue a request


In Microsoft Dynamics AX 2012, you construct and configure an instance of a service client object by
using code similar to the following example.
// Retrieve the X++ type for the Bing service client object.
clientType =
CLRInterop::getType("Contoso.ServiceReferences.BingV2ServiceReference.BingPortTypeClient");
// Use the AifUtil class to create an instance of the service client object.
_client = AifUtil::CreateServiceClient(clientType);


Running the job
Jobs run on the client by default. If you use a Web service from an X++ class, remember to use the
client or server method modifiers, or set the RunOn property on a specific class, to specify the
location where the code is to be executed.
Create a new job. In the Jobs Editor, enter the following X++ code.
// Job to run a Bing search
// Search for “Dynamics AX”
static void CallBingService(Args _args)
{
     #define.AppId("Your AppID goes here")


    // variable for service client
      ClrObject clientType;
     // variable for service client type
     Contoso.ServiceReferences.BingV2ServiceReference.BingPortTypeClient _client;


// variables for web query objects
     Contoso.ServiceReferences.BingV2ServiceReference.SearchRequest request;
     Contoso.ServiceReferences.BingV2ServiceReference.SourceType[] sourceTypes;
     Contoso.ServiceReferences.BingV2ServiceReference.SearchResponse response;
     Contoso.ServiceReferences.BingV2ServiceReference.WebResponse webResponse;
     Contoso.ServiceReferences.BingV2ServiceReference.WebResult[] webResults;
     Contoso.ServiceReferences.BingV2ServiceReference.WebResult webResult;


     int integer;
     str string;
     System.Exception ex;

     new InteropPermission(InteropKind::ClrInterop).assert();


8

CONSUMING WEB SERVICES
// Always try and catch errors as CLR exceptions
      try
      {
          // Retrieve the X++ type for the Bing service client object.
        clientType =
CLRInterop::getType("Contoso.ServiceReferences.BingV2ServiceReference.BingPortTypeClient");
          // Use the AifUtil class to create an instance of the service client object.
          _client = AifUtil::CreateServiceClient(clientType);


          // Create the request
          request = new Contoso.ServiceReferences.BingV2ServiceReference.SearchRequest();
          request.set_AppId(#AppId);
          request.set_Query("Dynamics AX");
          sourceTypes = new Contoso.ServiceReferences.BingV2ServiceReference.SourceType[1]();
          sourceTypes.SetValue(Contoso.ServiceReferences.BingV2ServiceReference.SourceType::Web,
0);
          request.set_Sources(sourceTypes);


          // Configure the response
           response = _client.Search(request);


          webResponse = response.get_Web();


          // Get the search results
          webResults = webResponse.get_Results();
          webResult = webResults.GetValue(0);


          // Display the results in the Infolog
          integer = webResponse.get_Total();
          info(strFmt("%1 total web results.", integer));
          integer = webResults.get_Count();
          info(strFmt("%1 results in response.", integer));
          info("");
          info("First result:");
          string = webResult.get_Title();
          info(strFmt("Title: %1", string));
          string = webResult.get_Description();
          info(strFmt("Description: %1", string));
          string = webResult.get_Url();
          info(strFmt("Url: %1", string));
      }
      catch(Exception::CLRError)
      {
          // handle the exception
          ex = CLRInterop::getLastException();
          info(ex.ToString());
      }
}




                                                                                                   9

                                                                           CONSUMING WEB SERVICES
Note that after the job runs, the following Infolog is displayed.




10

CONSUMING WEB SERVICES
Microsoft Dynamics is a line of integrated, adaptable business management solutions that enables you and your
people to make business decisions with greater confidence. Microsoft Dynamics works like and with familiar
Microsoft software, automating and streamlining financial, customer relationship and supply chain processes in a
way that helps you drive business success.


U.S. and Canada Toll Free 1-888-477-7989
Worldwide +1-701-281-6500
www.microsoft.com/dynamics




This document is provided “as-is.” Information and views expressed in this document, including URL and other
Internet Web site references, may change without notice. You bear the risk of using it.
Some examples depicted herein are provided for illustration only and are fictitious. No real association or
connection is intended or should be inferred.
This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You
may copy and use this document for your internal, reference purposes. You may modify this document for your
internal, reference purposes.

© 2011 Microsoft Corporation. All rights reserved.

Microsoft, the Microsoft Dynamics Logo, Microsoft Dynamics, Visual Studio, Visual C#, and Bing are trademarks of
the Microsoft group of companies.

All other trademarks are property of their respective owners.




                                                                                                                   11

                                                                                       CONSUMING WEB SERVICES

Contenu connexe

Tendances

SAP Process Mining in Action: Hear from Two Customers
SAP Process Mining in Action: Hear from Two CustomersSAP Process Mining in Action: Hear from Two Customers
SAP Process Mining in Action: Hear from Two CustomersCelonis
 
Private Equity Value Creation Carve Outs, Divestitures and mergers
Private Equity Value Creation Carve Outs, Divestitures and mergersPrivate Equity Value Creation Carve Outs, Divestitures and mergers
Private Equity Value Creation Carve Outs, Divestitures and mergersTom Laszewski
 
Introduction to ITIL v3 Foundation exam
Introduction to ITIL v3 Foundation examIntroduction to ITIL v3 Foundation exam
Introduction to ITIL v3 Foundation examKadimil
 
Cloud Migration, Application Modernization and Security for Partners
Cloud Migration, Application Modernization and Security for PartnersCloud Migration, Application Modernization and Security for Partners
Cloud Migration, Application Modernization and Security for PartnersAmazon Web Services
 
MLOps journey at Swisscom: AI Use Cases, Architecture and Future Vision
MLOps journey at Swisscom: AI Use Cases, Architecture and Future VisionMLOps journey at Swisscom: AI Use Cases, Architecture and Future Vision
MLOps journey at Swisscom: AI Use Cases, Architecture and Future VisionBATbern
 
Azure Arc Overview from Microsoft
Azure Arc Overview from MicrosoftAzure Arc Overview from Microsoft
Azure Arc Overview from MicrosoftDavid J Rosenthal
 
The Nielsen Company BI COE: A Case Study
The Nielsen Company BI COE: A Case StudyThe Nielsen Company BI COE: A Case Study
The Nielsen Company BI COE: A Case StudyJohn Boyer
 
Cloud Adoption Framework Define Your Cloud Strategy and Accelerate Results
Cloud Adoption Framework Define Your Cloud Strategy and Accelerate Results Cloud Adoption Framework Define Your Cloud Strategy and Accelerate Results
Cloud Adoption Framework Define Your Cloud Strategy and Accelerate Results Amazon Web Services
 
GEA-NZ v3.1 Infrastructure Reference Model and Taxonomy
GEA-NZ v3.1 Infrastructure Reference Model and TaxonomyGEA-NZ v3.1 Infrastructure Reference Model and Taxonomy
GEA-NZ v3.1 Infrastructure Reference Model and TaxonomyRegine Deleu
 
CAF presentation 09 16-2020
CAF presentation 09 16-2020CAF presentation 09 16-2020
CAF presentation 09 16-2020Michael Nichols
 
Building A Cloud Strategy PowerPoint Presentation Slides
Building A Cloud Strategy PowerPoint Presentation SlidesBuilding A Cloud Strategy PowerPoint Presentation Slides
Building A Cloud Strategy PowerPoint Presentation SlidesSlideTeam
 
On-premise to Microsoft Azure Cloud Migration.
 On-premise to Microsoft Azure Cloud Migration. On-premise to Microsoft Azure Cloud Migration.
On-premise to Microsoft Azure Cloud Migration.Emtec Inc.
 
Alteryx Architecture
Alteryx ArchitectureAlteryx Architecture
Alteryx ArchitectureVivek Mohan
 
Presentation GEA-NZ v3.0
Presentation GEA-NZ v3.0Presentation GEA-NZ v3.0
Presentation GEA-NZ v3.0Regine Deleu
 
The Paved Road at Netflix
The Paved Road at NetflixThe Paved Road at Netflix
The Paved Road at NetflixDianne Marsh
 
IT - Enterprise Service Operation Center
IT - Enterprise Service Operation CenterIT - Enterprise Service Operation Center
IT - Enterprise Service Operation CenterSameer Paradia
 
Microsoft Cloud Adoption Framework for Azure: Thru Partner Governance Workshop
Microsoft Cloud Adoption Framework for Azure: Thru Partner Governance WorkshopMicrosoft Cloud Adoption Framework for Azure: Thru Partner Governance Workshop
Microsoft Cloud Adoption Framework for Azure: Thru Partner Governance WorkshopNicholas Vossburg
 
Driving the Telecom Digital Transformation through Open Digital Architecture
Driving the Telecom Digital Transformation through Open Digital ArchitectureDriving the Telecom Digital Transformation through Open Digital Architecture
Driving the Telecom Digital Transformation through Open Digital ArchitectureSanjeewaRavi
 

Tendances (20)

SAP Process Mining in Action: Hear from Two Customers
SAP Process Mining in Action: Hear from Two CustomersSAP Process Mining in Action: Hear from Two Customers
SAP Process Mining in Action: Hear from Two Customers
 
Private Equity Value Creation Carve Outs, Divestitures and mergers
Private Equity Value Creation Carve Outs, Divestitures and mergersPrivate Equity Value Creation Carve Outs, Divestitures and mergers
Private Equity Value Creation Carve Outs, Divestitures and mergers
 
Introduction to ITIL v3 Foundation exam
Introduction to ITIL v3 Foundation examIntroduction to ITIL v3 Foundation exam
Introduction to ITIL v3 Foundation exam
 
Cloud Migration, Application Modernization and Security for Partners
Cloud Migration, Application Modernization and Security for PartnersCloud Migration, Application Modernization and Security for Partners
Cloud Migration, Application Modernization and Security for Partners
 
MLOps journey at Swisscom: AI Use Cases, Architecture and Future Vision
MLOps journey at Swisscom: AI Use Cases, Architecture and Future VisionMLOps journey at Swisscom: AI Use Cases, Architecture and Future Vision
MLOps journey at Swisscom: AI Use Cases, Architecture and Future Vision
 
Azure Arc Overview from Microsoft
Azure Arc Overview from MicrosoftAzure Arc Overview from Microsoft
Azure Arc Overview from Microsoft
 
The Nielsen Company BI COE: A Case Study
The Nielsen Company BI COE: A Case StudyThe Nielsen Company BI COE: A Case Study
The Nielsen Company BI COE: A Case Study
 
Cloud Adoption Framework Define Your Cloud Strategy and Accelerate Results
Cloud Adoption Framework Define Your Cloud Strategy and Accelerate Results Cloud Adoption Framework Define Your Cloud Strategy and Accelerate Results
Cloud Adoption Framework Define Your Cloud Strategy and Accelerate Results
 
GEA-NZ v3.1 Infrastructure Reference Model and Taxonomy
GEA-NZ v3.1 Infrastructure Reference Model and TaxonomyGEA-NZ v3.1 Infrastructure Reference Model and Taxonomy
GEA-NZ v3.1 Infrastructure Reference Model and Taxonomy
 
CAF presentation 09 16-2020
CAF presentation 09 16-2020CAF presentation 09 16-2020
CAF presentation 09 16-2020
 
Building A Cloud Strategy PowerPoint Presentation Slides
Building A Cloud Strategy PowerPoint Presentation SlidesBuilding A Cloud Strategy PowerPoint Presentation Slides
Building A Cloud Strategy PowerPoint Presentation Slides
 
On-premise to Microsoft Azure Cloud Migration.
 On-premise to Microsoft Azure Cloud Migration. On-premise to Microsoft Azure Cloud Migration.
On-premise to Microsoft Azure Cloud Migration.
 
Alteryx Architecture
Alteryx ArchitectureAlteryx Architecture
Alteryx Architecture
 
Presentation GEA-NZ v3.0
Presentation GEA-NZ v3.0Presentation GEA-NZ v3.0
Presentation GEA-NZ v3.0
 
The Paved Road at Netflix
The Paved Road at NetflixThe Paved Road at Netflix
The Paved Road at Netflix
 
IT - Enterprise Service Operation Center
IT - Enterprise Service Operation CenterIT - Enterprise Service Operation Center
IT - Enterprise Service Operation Center
 
Microsoft Cloud Adoption Framework for Azure: Thru Partner Governance Workshop
Microsoft Cloud Adoption Framework for Azure: Thru Partner Governance WorkshopMicrosoft Cloud Adoption Framework for Azure: Thru Partner Governance Workshop
Microsoft Cloud Adoption Framework for Azure: Thru Partner Governance Workshop
 
Driving the Telecom Digital Transformation through Open Digital Architecture
Driving the Telecom Digital Transformation through Open Digital ArchitectureDriving the Telecom Digital Transformation through Open Digital Architecture
Driving the Telecom Digital Transformation through Open Digital Architecture
 
It service management
It service managementIt service management
It service management
 
Demystifying identity on AWS
Demystifying identity on AWSDemystifying identity on AWS
Demystifying identity on AWS
 

Similaire à Consuming web services_ax2012

Creating & consuming simple web service
Creating & consuming simple web serviceCreating & consuming simple web service
Creating & consuming simple web serviceAbhijit B.
 
Build Message-Based Web Services for SOA
Build Message-Based Web Services for SOABuild Message-Based Web Services for SOA
Build Message-Based Web Services for SOAJeffrey Hasan
 
How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi...
 How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi... How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi...
How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi...Aimore Technologies
 
Go Serverless with Cosmos DB, Azure Functions and Blazor
Go Serverless with Cosmos DB, Azure Functions and BlazorGo Serverless with Cosmos DB, Azure Functions and Blazor
Go Serverless with Cosmos DB, Azure Functions and BlazorTimothy McAliley
 
Application integration framework & Adaptor ppt
Application integration framework & Adaptor pptApplication integration framework & Adaptor ppt
Application integration framework & Adaptor pptAditya Negi
 
IBM Innovate 2013: Making Rational HATS a Strategic Investment
IBM Innovate 2013: Making Rational HATS a Strategic InvestmentIBM Innovate 2013: Making Rational HATS a Strategic Investment
IBM Innovate 2013: Making Rational HATS a Strategic InvestmentStrongback Consulting
 
Pg. 03Question Three Assignment 3Deadline Sunda.docx
Pg. 03Question Three Assignment 3Deadline Sunda.docxPg. 03Question Three Assignment 3Deadline Sunda.docx
Pg. 03Question Three Assignment 3Deadline Sunda.docxJUST36
 
Pg. 03Question Three Assignment 3Deadline Sunda.docx
Pg. 03Question Three Assignment 3Deadline Sunda.docxPg. 03Question Three Assignment 3Deadline Sunda.docx
Pg. 03Question Three Assignment 3Deadline Sunda.docxkarlhennesey
 
A SharePoint Developers Guide to Project Server
A SharePoint Developers Guide to Project ServerA SharePoint Developers Guide to Project Server
A SharePoint Developers Guide to Project ServerAlexander Burton
 
Deep Dive on Serverless Web Applications - AWS May 2016 Webinar Series
Deep Dive on Serverless Web Applications - AWS May 2016 Webinar SeriesDeep Dive on Serverless Web Applications - AWS May 2016 Webinar Series
Deep Dive on Serverless Web Applications - AWS May 2016 Webinar SeriesAmazon Web Services
 
Making Rational HATS a Strategic Investment
Making Rational HATS a Strategic InvestmentMaking Rational HATS a Strategic Investment
Making Rational HATS a Strategic InvestmentStrongback Consulting
 
16 asp.net session23
16 asp.net session2316 asp.net session23
16 asp.net session23Vivek chan
 

Similaire à Consuming web services_ax2012 (20)

Creating & consuming simple web service
Creating & consuming simple web serviceCreating & consuming simple web service
Creating & consuming simple web service
 
Web services in ax 2012
Web services in ax 2012Web services in ax 2012
Web services in ax 2012
 
Build Message-Based Web Services for SOA
Build Message-Based Web Services for SOABuild Message-Based Web Services for SOA
Build Message-Based Web Services for SOA
 
How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi...
 How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi... How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi...
How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi...
 
Go Serverless with Cosmos DB, Azure Functions and Blazor
Go Serverless with Cosmos DB, Azure Functions and BlazorGo Serverless with Cosmos DB, Azure Functions and Blazor
Go Serverless with Cosmos DB, Azure Functions and Blazor
 
Application integration framework & Adaptor ppt
Application integration framework & Adaptor pptApplication integration framework & Adaptor ppt
Application integration framework & Adaptor ppt
 
IBM Innovate 2013: Making Rational HATS a Strategic Investment
IBM Innovate 2013: Making Rational HATS a Strategic InvestmentIBM Innovate 2013: Making Rational HATS a Strategic Investment
IBM Innovate 2013: Making Rational HATS a Strategic Investment
 
32916
3291632916
32916
 
Pg. 03Question Three Assignment 3Deadline Sunda.docx
Pg. 03Question Three Assignment 3Deadline Sunda.docxPg. 03Question Three Assignment 3Deadline Sunda.docx
Pg. 03Question Three Assignment 3Deadline Sunda.docx
 
Pg. 03Question Three Assignment 3Deadline Sunda.docx
Pg. 03Question Three Assignment 3Deadline Sunda.docxPg. 03Question Three Assignment 3Deadline Sunda.docx
Pg. 03Question Three Assignment 3Deadline Sunda.docx
 
A SharePoint Developers Guide to Project Server
A SharePoint Developers Guide to Project ServerA SharePoint Developers Guide to Project Server
A SharePoint Developers Guide to Project Server
 
Mvc summary
Mvc summaryMvc summary
Mvc summary
 
Fire up your mobile app!
Fire up your mobile app!Fire up your mobile app!
Fire up your mobile app!
 
Deep Dive on Serverless Web Applications - AWS May 2016 Webinar Series
Deep Dive on Serverless Web Applications - AWS May 2016 Webinar SeriesDeep Dive on Serverless Web Applications - AWS May 2016 Webinar Series
Deep Dive on Serverless Web Applications - AWS May 2016 Webinar Series
 
Intro to asp.net mvc 4 with visual studio
Intro to asp.net mvc 4 with visual studioIntro to asp.net mvc 4 with visual studio
Intro to asp.net mvc 4 with visual studio
 
Rutgers - Active Server Pages
Rutgers - Active Server PagesRutgers - Active Server Pages
Rutgers - Active Server Pages
 
Making Rational HATS a Strategic Investment
Making Rational HATS a Strategic InvestmentMaking Rational HATS a Strategic Investment
Making Rational HATS a Strategic Investment
 
Siebel Web Service
Siebel Web ServiceSiebel Web Service
Siebel Web Service
 
16 asp.net session23
16 asp.net session2316 asp.net session23
16 asp.net session23
 
XCC 9.0 Whats New
XCC 9.0 Whats NewXCC 9.0 Whats New
XCC 9.0 Whats New
 

Dernier

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 

Dernier (20)

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 

Consuming web services_ax2012

  • 1. Microsoft Dynamics AX 2012 ® Consuming Web Services White Paper Microsoft Dynamics AX 2012 introduces a new model for how to consume external Web services. This white paper describes how to reference a Web service and provides example code that demonstrates how to use the service in X++. Date: January 2011 Author: Jim Travis, Senior Writer and Nima Kamoosi, Senior Developer, Application Integration Framework Send suggestions and comments about this document to adocs@microsoft.com. Please include the title with your feedback.
  • 2. Table of Contents Introduction ................................................................................................ 3 Audience ..................................................................................................... 3 Prerequisites............................................................................................... 3 Using the Bing API ...................................................................................... 3 Install the Visual Studio tools ..................................................................... 4 Create the service project ........................................................................... 4 Add the service reference ...................................................................................................... 5 Add the project to the AOT ..................................................................................................... 6 Specify the deployment properties .......................................................................................... 6 Verify the service reference .................................................................................................... 7 Using the Web service ................................................................................. 8 Creating and configuring a service client object ........................................................................ 8 Running the job .................................................................................................................... 8 2 CONSUMING WEB SERVICES
  • 3. Introduction The previous version of Microsoft Dynamics® AX enabled you to consume external Web services from X++ code and to consume Web services hosted by Microsoft Dynamics AX from .NET Framework languages, such as Microsoft Visual C#®. To use a Web service, you added a reference in the Web references form, as described in the Consume Web Services topic on MSDN (http://msdn.microsoft.com/en-us/library/cc654149.aspx). Microsoft Dynamics AX 2012 continues to enable Web services scenarios. However, you now use Microsoft Visual Studio to create and add a reference to a Web service. This white paper walks you through creating a reference to the Bing™ API Web service and provides sample code for a job that consumes the service. Audience This white paper is intended for developers who integrate Web services with Microsoft Dynamics AX. Prerequisites To benefit from this white paper, you should have experience in the following areas:  Writing code in .NET Framework languages or X++  Using Microsoft® Visual Studio®  Setting up Microsoft Dynamics AX You must have Microsoft Visual Studio 2010 installed on the computer that is running Microsoft Dynamics AX 2012. Using the Bing API To use the Bing API Web service, you must have the necessary resources and provision your application by getting an AppID. For more information about the Bing API and to create an AppID, see the Bing Developer Center (http://www.bing.com/developers). 3 CONSUMING WEB SERVICES
  • 4. Install the Visual Studio tools Follow these steps to install the Visual Studio tools for Microsoft Dynamics AX: 1. Run Microsoft Dynamics AX 2012 setup. 2. Under Install, click Microsoft Dynamics AX components. 3. Click Next to go to the Add or modify components page. 4. Under Developer Tools, select Visual Studio Tools. 5. Click Next to step through the remaining setup pages. 6. Click Install to install the tools. 7. Click Finish to close the wizard. 8. Exit setup. Create the service project Microsoft Visual Studio 2010 can create a project that Microsoft Dynamics AX can use to build a .NET assembly (and its configuration file) that exposes types from a Web service reference. Follow these steps to create a project with the Bing API Web service reference: 1. Open Microsoft Visual Studio 2010. 2. Create a new Visual C# Class Library project. (You can use other .NET Framework languages, but this walkthrough uses Visual C#.) 3. For the project name, type “Contoso.ServiceReferences”. 4 CONSUMING WEB SERVICES
  • 5. 4. Click OK to create the project. Add the service reference Follow these steps to add a reference to the Bing API Web service to your project: 1. In Solution Explorer, right-click the project name, and then click Add Service Reference. 2. In the Add Service Reference dialog box, type the URL for the Web service in the Address box. The URL for the Bing API Web service is: http://api.bing.net/search.wsdl?AppID=YourAppId&Version=2.2 Replace the YourAppId text in the URL with your AppID. 3. Click Go to locate the service. 5 CONSUMING WEB SERVICES
  • 6. 4. Click OK. Add the project to the AOT Next, add the project to the Application Object Tree (AOT) in Microsoft Dynamics AX. In Solution Explorer, right-click the project name, and then click Add Contoso.ServiceReferences to AOT. Microsoft Dynamics AX imports the project and builds it. Specify the deployment properties Next, set the deployment properties in Visual Studio. In the Properties window, specify the following values for the deployment properties. 6 CONSUMING WEB SERVICES
  • 7. Name Value Deploy to client Yes Deploy to EP No Deploy to server Yes Deploy to SSRS No Verify the service reference Follow these steps to verify that the reference to the Bing API Web service appears in the AOT: 1. Restart the Microsoft Dynamics AX client. 2. Open the development workspace. 3. In the AOT, browse to Visual Studio Projects > C Sharp Projects. 4. Verify that Contoso.Servicereferences is listed as a project. 7 CONSUMING WEB SERVICES
  • 8. Using the Web service You can now use the Bing API Web service. In this section, you will create a job that performs a Bing search. Creating and configuring a service client object To consume a Web service in Microsoft Dynamics AX 2009, you added a service reference and then created and used the service client object by using code similar to the following example. WindowsLiveSearch.MSNSearchPortTypeClient searchService; // declare the service object ... searchService = new WindowsLiveSearch.MSNSearchPortTypeClient(); // create the service object searchResponse = searchService.Search(searchRequest); // use the service to issue a request In Microsoft Dynamics AX 2012, you construct and configure an instance of a service client object by using code similar to the following example. // Retrieve the X++ type for the Bing service client object. clientType = CLRInterop::getType("Contoso.ServiceReferences.BingV2ServiceReference.BingPortTypeClient"); // Use the AifUtil class to create an instance of the service client object. _client = AifUtil::CreateServiceClient(clientType); Running the job Jobs run on the client by default. If you use a Web service from an X++ class, remember to use the client or server method modifiers, or set the RunOn property on a specific class, to specify the location where the code is to be executed. Create a new job. In the Jobs Editor, enter the following X++ code. // Job to run a Bing search // Search for “Dynamics AX” static void CallBingService(Args _args) { #define.AppId("Your AppID goes here") // variable for service client ClrObject clientType; // variable for service client type Contoso.ServiceReferences.BingV2ServiceReference.BingPortTypeClient _client; // variables for web query objects Contoso.ServiceReferences.BingV2ServiceReference.SearchRequest request; Contoso.ServiceReferences.BingV2ServiceReference.SourceType[] sourceTypes; Contoso.ServiceReferences.BingV2ServiceReference.SearchResponse response; Contoso.ServiceReferences.BingV2ServiceReference.WebResponse webResponse; Contoso.ServiceReferences.BingV2ServiceReference.WebResult[] webResults; Contoso.ServiceReferences.BingV2ServiceReference.WebResult webResult; int integer; str string; System.Exception ex; new InteropPermission(InteropKind::ClrInterop).assert(); 8 CONSUMING WEB SERVICES
  • 9. // Always try and catch errors as CLR exceptions try { // Retrieve the X++ type for the Bing service client object. clientType = CLRInterop::getType("Contoso.ServiceReferences.BingV2ServiceReference.BingPortTypeClient"); // Use the AifUtil class to create an instance of the service client object. _client = AifUtil::CreateServiceClient(clientType); // Create the request request = new Contoso.ServiceReferences.BingV2ServiceReference.SearchRequest(); request.set_AppId(#AppId); request.set_Query("Dynamics AX"); sourceTypes = new Contoso.ServiceReferences.BingV2ServiceReference.SourceType[1](); sourceTypes.SetValue(Contoso.ServiceReferences.BingV2ServiceReference.SourceType::Web, 0); request.set_Sources(sourceTypes); // Configure the response response = _client.Search(request); webResponse = response.get_Web(); // Get the search results webResults = webResponse.get_Results(); webResult = webResults.GetValue(0); // Display the results in the Infolog integer = webResponse.get_Total(); info(strFmt("%1 total web results.", integer)); integer = webResults.get_Count(); info(strFmt("%1 results in response.", integer)); info(""); info("First result:"); string = webResult.get_Title(); info(strFmt("Title: %1", string)); string = webResult.get_Description(); info(strFmt("Description: %1", string)); string = webResult.get_Url(); info(strFmt("Url: %1", string)); } catch(Exception::CLRError) { // handle the exception ex = CLRInterop::getLastException(); info(ex.ToString()); } } 9 CONSUMING WEB SERVICES
  • 10. Note that after the job runs, the following Infolog is displayed. 10 CONSUMING WEB SERVICES
  • 11. Microsoft Dynamics is a line of integrated, adaptable business management solutions that enables you and your people to make business decisions with greater confidence. Microsoft Dynamics works like and with familiar Microsoft software, automating and streamlining financial, customer relationship and supply chain processes in a way that helps you drive business success. U.S. and Canada Toll Free 1-888-477-7989 Worldwide +1-701-281-6500 www.microsoft.com/dynamics This document is provided “as-is.” Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it. Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or should be inferred. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. You may modify this document for your internal, reference purposes. © 2011 Microsoft Corporation. All rights reserved. Microsoft, the Microsoft Dynamics Logo, Microsoft Dynamics, Visual Studio, Visual C#, and Bing are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners. 11 CONSUMING WEB SERVICES