AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 25.01.2008, 15:10   #1  
Blog bot is offline
Blog bot
Участник
 
25,640 / 848 (80) +++++++
Регистрация: 28.10.2006
Consuming "CustomerService" Web Service
Источник: http://blogs.msdn.com/aif/archive/20...-c-client.aspx
==============

Version: Dynamics AX 4 SP2.

In Dynamics AX 4 SP2, basic framework support for update and delete functionality has been added to the pre-existing framework support for create, read and find functionality. This blog illustrates how the pre-existing functionality as well as the new update and delete functionality can be consumed from a sample C# web service client. The same functionality is accessible through any other transport supported by AIF, including the BizTalk adapter, the MSMQ adapter and the file system adapter.
The samples below use the Axd class AxdCustomer, which ships as part of Dynamics AX 4 SP2 and provides update and delete functionality out of the box. [For a full program sample see attachment "CustomerServiceTest.cs".]

0. Disclaimer
· All code used below is meant for illustration purposes only and not intended for use in production. The following disclaimer applied to all code used in this blog:

Copyright (c) Microsoft Corporation. All rights reserved. THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. USE AND REDISTRIBUTION OF THIS CODE, WITH OR WITHOUT MODIFICATION, IS HEREBY PERMITTED.

1. Prerequisites
· Install and configure Dynamics AX 4 SP2
· Install and configure AIF Web Services according to AIF documentation; this includes:
o IIS configuration (to host generated AIF web services)
o Configuration of AIF web site (AIF form "Web sites")
o Etc.
As a result of this configuration it must be possible to generate and deploy Dynamics AX web services.
2. Configure & Generate AIF Web Service "CustomerService"
· In the table on the “Action” form (Basic -> Setup -> Application Integration Framework -> Action), check “Enabled” and “Web Method Enabled” in the rows for the following actions:
o createListCustomer
o readListCustomer
o deleteListCustomer
· On the “Action” form, click “Generate” to generate web service(s)
· Verify that the WSDL for CustomerService is available (e.g. http://:/DynamicsWebService/CustomerService.asmx?wsdl; for details see AIF documentation)
3. Configure Additional AIF Parameters
· Create Local Endpoint "Contoso" (Basic -> Setup -> Application Integration Framework -> Local Endpoints)
· Create and configure Endpoint "NorthwindTraders" (Basic -> Setup -> Application Integration Framework -> Endpoints)
o Settings (for details and additional options for endpoint configuration see AIF documentation):
§ Name: “Nortwind Traders”
§ Constraints: No constraints
§ User: Valid Dynamics AX user
§ Local Endpoint: "Contoso"
o Save and activate Endpoint “NorthwindTraders”
o Configure action policies (enable createListCustomer, readListCustomer, deleteListCustomer)
o Configure data policies for these three actions (allow all data fields: Set -> Enable All)
4. Create Sample C# Web Service Client (Visual Studio 2005)
· Open Visual Studio 2005
· Create project “WebServiceTests” (console application)
· Add web reference to CustomerService to project (use URL for CustomerService WSDL, see above)
· Implement code to exercise customer service API (adjust names to actual names):

o Use code similar to the following snippet to create customer service proxy:

// assumes namespace “WebServiceTests”
using WebServiceTests.CustomerService;
...

CustomerService.CustomerService service =
new CustomerService.CustomerService();
if (null == this.service) {
throw new Exception(
"Cannot instantiate service.");
}
service.UseDefaultCredentials = true;

o Use code similar to the following snippet to a create customer (this has not changed in Dynamics AX 4 SP2).

AxdCustomer customer = new AxdCustomer();

// create & populate customer record (w/demo data)
customer.CustTable = new AxdEntity_CustTable[1];
customer.CustTable[0] = new AxdEntity_CustTable();
customer.CustTable[0].CustGroup = "40";
customer.CustTable[0].Name = "Customer";

// consume AX web service to create customer
EntityKey[] entityKey = null;
entityKey = service.createListCustomer(
getDocumentContext(), customer);

o Use code similar to the following snippet to read the newly created customer record (this has not changed in Dynamics AX 4 SP2):

customer = service.readListCustomer(
getDocumentContext(), entityKey);

o Use code similar to the following snippet to update name and zip code of the newly created customer record (this is new functionality, introduced on Dynamics AX 4 SP2).
Notes:
§ In Dynamics AX 4.0 SP2, create actions can be overloaded with update functionality; in other words, create and createList actions can be used to update existing records. Explicit update actions are not generated by the Axd wizard nor are they shipped as part of any Dynamics AX 4.0 Axd classes out of the box. For Axd classes that ship out of the box, create and createList actions are used to implement update functionality instead (where updates are supported).
§ Update actions are implemented with document-centric service semantics; they assume the “whole documents” to be submitted as part of update requests – in the sample these documents are customer documents. Fields that are not set in the document will be reset in Dynamics AX to the equivalent of the “null” value for the respective type. If this is not desirable, it is recommended to read the whole document before updating it. Also note that the definition of a “whole document” depends on the respective endpoint that submits the document as part of an update request. Fields that the endpoint is not allowed to send as part of the update request (as per data policy definition), need not/cannot be sent as part of update requests. Thus, it is further recommended to synchronize the data policies for read and update (i.e. create) actions.

// modify customer name: append name with “X”
customer.CustTable[0].Name += "X";

// set customer zip code (using demo data)
customer.CustTable[0].ZipCode = "DK-3600";

// apply changes
service.createListCustomer(getDocumentContext(),
customer);

o Use code similar to the following snippet to delete the newly created customer record (this is new functionality, introduced on Dynamics AX 4 SP2).

service.deleteListCustomer(getDocumentContext(),
entityKey);

5. Try it out...


Источник: http://blogs.msdn.com/aif/archive/20...-c-client.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Теги
aif, ax4.0

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Consuming External Web Services (Dynamics AX 4) Blog bot DAX Blogs 0 19.02.2008 06:41
Inside Dynamics AX 4.0: The Web Framework Blog bot DAX Blogs 0 25.10.2007 03:04
Axapta Lessons: Creating an IBF Compliant Web Service for Axapta Blog bot DAX Blogs 0 28.10.2006 18:22
Pokluda: Outbound web service (AIF) Blog bot DAX Blogs 0 28.10.2006 17:43
Fred Shen: Consuming a Web Service in Dynamics AX 4 Blog bot DAX Blogs 0 28.10.2006 16:40
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 15:36.