Consuming Web Services



Similar documents
Deploying the Workspace Application for Microsoft SharePoint Online

Configuring a SQL Server Reporting Services scale-out deployment to run on a Network Load Balancing cluster

Developing Solutions for Microsoft Dynamics AX in a Shared AOS Development Environment

Accounting for stocked items on product receipts and vendor invoices

Windows Event Tracing in Microsoft Dynamics AX 2012

Configure Microsoft Dynamics AX Connector for Mobile Applications

Management Reporter Integration Guide for Microsoft Dynamics GP

Configuring budget planning for Microsoft Dynamics AX 2012 R2

Payment Processing Frequently Asked Questions. Microsoft Dynamics RMS

Update and Installation Guide for Microsoft Management Reporter 2.0 Feature Pack 1

Management Reporter Integration Guide for Microsoft Dynamics AX

Microsoft Dynamics AX 2012 Installation Guide. Microsoft Corporation Published: April 2011 This content is preliminary and is subject to change.

Deploy the client as an Azure RemoteApp program

Microsoft Dynamics CRM Adapter for Microsoft Dynamics GP

Retail Deployment Guide. Microsoft Dynamics AX 2012 Feature Pack

Performance data collection and analysis process

Timesheet audit trail and absence reporting for DCAA. Syed Ali May 2014

Credit Card Processing

Connector for Microsoft Dynamics Configuration Guide for Microsoft Dynamics SL

Workflow approval via

Microsoft Dynamics GP. Business Analyzer

Retail POS User s Guide. Microsoft Dynamics AX for Retail

Microsoft Dynamics AX 2009 Installation Guide. Microsoft Corporation Published: November 2009

Windows Server Update Services 3.0 SP2 Step By Step Guide

MicrosoftDynam ics GP TenantServices Installation and Adm inistration Guide

Microsoft Dynamics GP SQL Server Reporting Services Guide

Changes to credit card processing in Microsoft Dynamics AX 2012 R2

System Requirements for Microsoft Dynamics NAV 2013 R2

Business Portal for Microsoft Dynamics GP Field Service Suite

Credit Card Processing

Features for France. Microsoft Corporation. Published: November 2006

Entity store. Microsoft Dynamics AX 2012 R3

Microsoft Dynamics GP Release

Feature for India (Third-party invoice)

Business Intelligence in Microsoft Dynamics AX 2012

Writers: Joanne Hodgins, Omri Bahat, Morgan Oslake, and Matt Hollingsworth

K2 Designer for SharePoint Hands-On Exercise - Leave Request process

Connector for Microsoft Dynamics Configuration Guide for Microsoft Dynamics AX

Microsoft Dynamics AX 2012 System Requirements. Microsoft Corporation Published: August 2011

Microsoft Dynamics NAV

Authoring for System Center 2012 Operations Manager

Microsoft Dynamics AX 2012 System Requirements. Microsoft Corporation Published: November 2011

EventTracker: Support to Non English Systems

Lab Answer Key for Module 9: Active Directory Domain Services. Table of Contents Lab 1: Exploring Active Directory Domain Services 1

Connector for Microsoft Dynamics Configuration Guide for Microsoft Dynamics NAV

Lab Answer Key for Module 11: Managing Transactions and Locks

Customizing Remote Desktop Web Access by Using Windows SharePoint Services Stepby-Step

SQL Server 2005 Reporting Services (SSRS)

Installing Windows Rights Management Services with Service Pack 2 Step-by- Step Guide

Step-by-Step Guide for Microsoft Advanced Group Policy Management 4.0

Exclaimer Alias Manager for Exchange Deployment Guide - Exclaimer Alias Manager for Exchange Outlook Add-In

Stellar Phoenix Exchange Server Backup

Microsoft Dynamics GP. econnect Installation and Administration Guide Release 9.0

How to Prepare for the Upgrade to Microsoft Dynamics CRM 2013 (On-premises)

Deploying Remote Desktop IP Virtualization Step-by-Step Guide

How To Install Outlook Addin On A 32 Bit Computer

Creating and Deploying Active Directory Rights Management Services Templates Step-by-Step Guide

MICROSOFT STEP BY STEP INTERACTIVE VERSION 3.0 ADMINISTRATION GUIDE

Using the vcenter Orchestrator Plug-In for vsphere Auto Deploy 1.0

Business Portal for Microsoft Dynamics GP. Key Performance Indicators Release 10.0

Programmabilty. Programmability in Microsoft Dynamics AX Microsoft Dynamics AX White Paper

Microsoft Dynamics GP econnect Installation and Administration Guide

Integrate Cisco IronPort Web Security Appliance (WSA)

Integration with Active Directory

Microsoft Dynamics AX 2012 System Requirements. Microsoft Corporation Published: March 2012

Configuring Network Load Balancing with Cerberus FTP Server

Hyper-V Server 2008 Getting Started Guide

Microsoft Dynamics AX 2012 MorphX Enhancements

Code Review Installation Guide

Implementing and Supporting Windows Intune

AD RMS Step-by-Step Guide

Windows BitLocker Drive Encryption Step-by-Step Guide

RES IT Store Integration Guide: MS System Center

ENHANCE. The Style Sheet Tool for Microsoft Dynamics NAV. Microsoft Dynamics NAV 5.0. User s Guide

Connecting the RoleTailored Client over a Wide Area Network

A SharePoint Developer Introduction

Setup Guide: Server-side synchronization for CRM Online and Exchange Server

IBM Configuring Rational Insight and later for Rational Asset Manager

Administration Guide for the System Center Cloud Services Process Pack

Creating and Issuing the Workstation Authentication Certificate Template on the Certification Authority

Security Development Tool for Microsoft Dynamics AX 2012 WHITEPAPER

Interactive Timeline Visualization for Microsoft Dynamics NAV 2009 R2

Create a Balanced Scorecard

Overview of Web Services API

SPHOL325: SharePoint Server 2013 Search Connectors and Using BCS

Lab Answer Key for Module 1: Installing and Configuring Windows Server Table of Contents Lab 1: Configuring Windows Server

Administrator s Guide to deploying Engagement across multiple computers in a network using Microsoft Active Directory

Microsoft Lync Server 2010

Deploying Personal Virtual Desktops by Using RemoteApp and Desktop Connection Step-by-Step Guide

Business Portal for Microsoft Dynamics GP Project Time and Expense Administrator s Guide

Hyper-V Server 2008 Setup and Configuration Tool Guide

Deploying Remote Desktop Web Access with Remote Desktop Connection Broker Step-by- Step Guide

DriveLock Quick Start Guide

Use the Microsoft Office Word Add-In to Create a Source Document Template for Microsoft Dynamics AX 2012 WHITEPAPER

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

The 2007 R2 Version of Microsoft Office Communicator Mobile for Windows Mobile: Frequently Asked Questions

StarWind iscsi SAN & NAS: Multipathing October 2012

Transcription:

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

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

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

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

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

Name Deploy to client Deploy to EP Deploy to server Deploy to SSRS Value Yes No Yes 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

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

// 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); 0); // 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, 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

Note that after the job runs, the following Infolog is displayed. 10

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