Error in Custom Service Class

Hello guys,

I did a custom service like this:

Contract Class where i defined all return parameters

[DataContractAttribute]

public class PurchAgreementContractLine

{

//AgreementLine

AgreementLineNum_PSN lineNumber;

CurrencyCode currencyCode;

ItemId itemId;

//PurchAgreementHeader

AgreementState agreementState;

EffectiveDate effectiveDate;

ExpirationDate expirationDate;

VendAccount vendAccount;

DataAreaId dataAreaId;

PurchAgreementId purchAgreementId;

//DirParty

Name vendorName;

//InventDim

EcoResItemSizeName sizeName;

EcoResItemColorName colorName;

EcoResItemStyleName styleName;

Description sizeDescription;

Description styleDescription;

//AgreementLineQuantityCommitment

UnitOfMeasureSymbol productUnitOfMeasure;

PriceUnit pricePerUnit;

//EcoResProductTranslation

EcoResDescription ecoResDescription;

}

for each parameter a parm method like this:

[DataMemberAttribute(‘Agreement State’)]

public AgreementState agreementState(AgreementState _agreementState = agreementState)

{

agreementState = _agreementState;

return agreementState;

}

Then a service class with exposed method findAgreement which returns the contract class:

class PurchAgreementListService

{

}

[AifCollectionTypeAttribute(’_legalEntity’, Types::String), //companyId

AifCollectionTypeAttribute(’_vendor’, Types::String),

AifCollectionTypeAttribute(‘return’, Types::Class, classStr(AVY0010_PurchAgreementContractLine)),

SysEntryPointAttribute(true)]

public List findAgreement( DataAreaId _legalEntity,

VendAccount _vendor,)

{

PurchAgreementContractLine agreementContractLine;

AgreementLine agreementLine;

List agreements;

Query q = new Query();

QueryRun qr;

QueryBuildDataSource qbds, qbds1;

agreements = new List(Types::Class);

qbds = q.addDataSource(tableNum(PurchAgreementHeader));

if (_vendor)

qbds.addRange(fieldNum(PurchAgreementHeader, VendAccount));

q.dataSourceTable(tableNum(PurchAgreementHeader)).addDataSource(tableNum(AgreementLine)).addLink(fieldNum(PurchAgreementHeader,RecId),fieldNum(AgreementLine,Agreement));

q.dataSourceTable(tableNum(AgreementLine)).addDataSource(tableNum(InventDim)).addLink(fieldNum(AgreementLine, InventDimId), fieldNum(InventDim, InventDimId));

qr = new QueryRun(q);

while (qr.next())

{

agreementLine = qr.get(tableNum(AgreementLine));

agreementContractLine = new PurchAgreementContractLine();

agreementContractLine.purchAgreementId(agreementLine.PurchAgreementHEader().PurchNumberSequence);

agreementContractLine.agreementState(agreementLine.PurchAgreementHEader().AgreementState);

agreementContractLine.vendAccount(agreementLine.PurchAgreementHeader().VendAccount);

agreementContractLine.vendorName(agreementLine.PurchAgreementHEader().vendName());

…

agreements.addEnd(agreementContractLine);

}

return agreements;

}

CIl incremental and full done, Registered the service, added to the service group, deployed and inbound port active:

when I try to invoke the service I got this error:

error CS0234: The type or namespace name ‘Application’ does not exist in the namespace ‘Microsoft.Dynamics.Ax’ (are you missing an assembly reference?)

Modifying the return type from type class

AifCollectionTypeAttribute(‘return’, Types::Class, classStr(AVY0010_PurchAgreementContractLine)),

to a List of Types:string it works without issues… any idea?

I suspect you don’t understand the purpose of AifCollectionTypeAttribute. It’s used to define the type of a collection, e.g. if you return a List and expect it to be translated to an array of string, therefore you declare that this list contains strings.

You declared AifCollectionTypeAttribute for both parameters, but none of them is a collection, so it doesn’t makes any sense. Remove them.

Also, please check whether there is an error message in AifService form (in the case when it doesn’t work).

Hi Martin,

tks you for your feedback, however:

  1. The PurchAgreementContractLine (AVY0010_PurchAgreementContractLine, missing prefix when copied to this post) is a

data contract class since has [DataContractAttribute] in class declaration

  1. No issue on aifservice form, I can see the service and operation

  2. you’re right, I deleted the AifCollectionTypeAttribute but the issue remains

If I change the return type from Class to string replacing datacontract class as list of strings it works, so the issue seems related to the returned datacontract class

Am I missing something in the data contract class, any other idea? tks

That it works if you declare the return type as a collection of strings (while providing a collection of objects) makes absolutely no sense to me. What the heck the service returns in that case?

even for me but it was only a test to check if the problem was the return type or something else…

may I send you this 2 classes?

Can you please answer my question and tell me what the service returns?