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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 24.01.2012, 00:09   #1  
wojzeh is offline
wojzeh
Участник
Аватар для wojzeh
Соотечественники
 
672 / 512 (19) +++++++
Регистрация: 27.04.2006
Адрес: Montreal
AX2012: сервисы и чудеса системного метода DictMethod.parameterCnt()
пытаюсь создать свой сервис и затем задеплоить его через сервисную группу, как написано в мануале What's New - Technical in Microsoft Dynamics® AX 2012 for Development в его 5 главе Chapter 5: Services and Application Integration.

Цитата:
Step by Step: Create the Data Contract Class
1.
Open Microsoft Dynamics AX 2012.
2.
Open a Developer workspace.
3.
Open the AOT.
4.
Create a new class named AddressFinder.
5.
Enhance the class by adding the [DataContractAttribute] attribute.
6.
Enter a method called Address which returns the address.
7.
Enhance the method by adding the [DataMemberAttribute] attribute.

X++:
[DataMemberAttribute] 
public str address() 
{
return "Demo Address"; 
}
Step by Step: Create the X++ Service Class
1.
Create a new class named AddressUtility. This is the service class.
2.
Create a public method named getNearestLocation. This method instantiates the AddressFinder object and returns the AddressFinder object.
3.
Enhance the class by adding the [SysEntryPointAttribute] attribute.

X++:
[SysEntryPointAttribute] 
public AddressFinder getNearestLocation() 
{ 
AddressFinder addressFinder = new AddressFinder(); 
return addressFinder; 
}
Step by Step: Create the Service
1.
Right-click the Services node in the AOT and select New Service.
2.
Change the Name property to AddressService.
3.
Set the Class property to AddressUtility.

4.
Expand the AddressService service node.
5.
Right-click the Operations node and select Add Operations.

6.
Check the Add checkbox and click OK.
7.
Right-click the Services Group node in the AOT and select New Service Group.
8.
Change the Name property to AddressServiceGroup.
9.
Drag the service under the service group node.
10.
Right-click the AddressServiceGroup service group and select Deploy service group.
на этой последней стадии получал ошибку о невалидности метода без какой бы то ни было дополнительной информации. по итогам дебаггинга немного докрутил метод в классе AifUtil.isValidDataMember, чтобы увидеть детали.

X++:
/// <summary>
///    Microsoft internal use only.
/// </summary>
/// <param name="dictMethod">An instance of the <c>SysDictMethod</c> class.</param>
/// <returns>A <c>boolean</c> Enumeration Type.</returns>
static boolean isValidDataMember(SysDictMethod dictMethod)
{
    // Alex Voytsekhovskiy (WMP) (2012/01/20) (Demande #)
    //-->
    Types   retType, parType;
    int     retId, parId;
    int     parCnt;
    boolean res, allRes;
    str     msg;
    ;
    res = dictMethod.compiledOk();
    if (!res)
    {
        msg = "Not complied";
        throw error(strfmt("%1.%2() is not valid DataMember; Errors: %3", dictMethod.parentName(), dictMethod.name(), msg));
    }        

    res = dictMethod.utilElementType() == UtilElementType::ClassInstanceMethod;
    if (!res)
    {    
        msg = "Not ClassInstanceMethod";
        throw error(strfmt("%1.%2() is not valid DataMember; Errors: %3", dictMethod.parentName(), dictMethod.name(), msg));
    }        

    res = dictMethod.accessSpecifier() == AccessSpecifier::public;
    if (!res)
    {    
        msg = "Not Public method";
        throw error(strfmt("%1.%2() is not valid DataMember; Errors: %3", dictMethod.parentName(), dictMethod.name(), msg));
    }        
    parCnt = dictMethod.parameterCnt();
    res =parCnt == 1;
    if (!res)
    {    
        msg = strFmt("Not One and only one input parameter = %1", parCnt);
        throw error(strfmt("%1.%2() is not valid DataMember; Errors: %3", dictMethod.parentName(), dictMethod.name(), msg));
    }        

    res = dictMethod.parameterOptional(1);
    if (!res)
    {    
        msg = "Parameter is not optional";
        throw error(strfmt("%1.%2() is not valid DataMember; Errors: %3", dictMethod.parentName(), dictMethod.name(), msg));
    }        
    retType = dictMethod.returnType();
    parType = dictMethod.parameterType(1);
    res = retType == parType;
    if (!res)
    {        
        msg = strfmt("Return type %1 does not match parameter type %2", retType, parType);
        throw error(strfmt("%1.%2() is not valid DataMember; Errors: %3", dictMethod.parentName(), dictMethod.name(), msg));
    }        
    retId = dictMethod.returnId();
    parId = dictMethod.parameterId(1);
    res = retId == parId;
    if (!res)
    {    
        msg = msg+"; "+ strfmt("Return Id %1 does not match parameter id %2", retId, parId);
        throw error(strfmt("%1.%2() is not valid DataMember; Errors: %3", dictMethod.parentName(), dictMethod.name(), msg));
    }        

    return res;
    //<--

//    return (
//        dictMethod.compiledOk() &&                                                  // Compile OK
//        dictMethod.utilElementType() == UtilElementType::ClassInstanceMethod &&     // Instance method
//        dictMethod.accessSpecifier() == AccessSpecifier::public &&                  // Public method
//        dictMethod.parameterCnt() == 1  &&                                          // One and only one input parameter
//        dictMethod.parameterOptional(1) &&                                          // Parameter is optional
//        dictMethod.returnType() == dictMethod.parameterType(1) &&                   // Return type matches parameter type
//        dictMethod.returnId() == dictMethod.parameterId(1));
}
сам метод, который не проходит проверку на количество параметров, вот:

X++:
[DataMemberAttribute]
public str address1(str s ='')
{
    return "Demo Address";
}
при этом дебаггер показывает следующее:
Нажмите на изображение для увеличения
Название: 2012-01-23_1449.png
Просмотров: 620
Размер:	72.0 Кб
ID:	7496

шутки ради нарисовал рядышком ещё один метод -- однояйцевый близнец предыдущего

X++:
[DataMemberAttribute]
str gimme(str s = '')
{
    ;
    return "gimme more";
}
с ним ошибок не возникает, и количество параметров = 1.

в этой связи вопрос: куда копать, и зачем методам, который выставляются через сервис вообще нужны параметры? (обратите внимание на проверки в методе)

компиляция, forward compilation, CIL, перезапуск клиента, сервера и прочие танцы с бубном уже исполнялись. спасибо.
__________________
Felix nihil admirari
Старый 24.01.2012, 13:16   #2  
sukhanchik is offline
sukhanchik
Administrator
Аватар для sukhanchik
MCBMSS
Злыдни
Лучший по профессии 2015
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
3,273 / 3466 (122) ++++++++++
Регистрация: 13.06.2004
Адрес: Москва
Перенес ответ в отдельную тему AX 2012 Создание сервиса по шагам
__________________
Возможно сделать все. Вопрос времени
Старый 26.02.2013, 14:58   #3  
MikeR is offline
MikeR
MCT
Аватар для MikeR
MCBMSS
Лучший по профессии 2015
Лучший по профессии 2014
 
1,628 / 627 (24) +++++++
Регистрация: 28.11.2005
Адрес: просто землянин
Дошел и мой черед до этого примера.
На самом деле все оказалось проще.
Покопавшись в стандарте, нашел что всего-то надо было добавить
X++:
[AifDocumentReadAttribute, SysEntryPointAttribute]
public AddressFinder getNearestLocation()
{
     AddressFinder addressFinder = new AddressFinder();
     return addressFinder;
}
и доступ можно получить через ссылку, а не через external name

У суханчика пример более расширенный.
__________________
Axapta book for developer
За это сообщение автора поблагодарили: Logger (1).
Теги
aif, ax2012, dictmethod, web сервис, webservice, законченный пример

 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
sumitax: AX2012 – One stop for all documentation released my Microsoft Blog bot DAX Blogs 0 26.09.2011 19:13
ukax: Microsoft Dynamics AX2012 - Partner Update Briefing Blog bot DAX Blogs 0 23.07.2011 20:15
sumitax: AX2012 Features – Financial Dimensions changes Blog bot DAX Blogs 0 12.05.2011 15:11
sumitax: AX2012 Training material download Blog bot DAX Blogs 0 11.04.2011 13:11
sumitax: AX2012 – Interview with Kees Hertogh – Microsoft’s Dynamics AX Product Director Blog bot DAX Blogs 1 26.03.2011 10:47
Опции темы Поиск в этой теме
Поиск в этой теме:

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

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

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

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 01:23.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.