Simple custom service implementation example ax 2012

Service class:
class VKOCalcService { }
[SysEntryPointAttribute(true),  AifCollectionTypeAttribute('return', Types::Class, classStr(VKOCalcContract)),  AifCollectionTypeAttribute('_calcContract', Types::Class, classStr(VKOCalcResponseContract))] public VKOCalcResponseContract calc(VKOCalcContract _calcContract) {     VKOCalcResponseContract response    = new VKOCalcResponseContract();     real                    result;     int                     a1          = _calcContract.parmArg1(),                             a2          = _calcContract.parmArg2();     switch (_calcContract.parmOperation())     {         case VKOCalcOperation::add:             result = a1 + a2;             break;         case VKOCalcOperation::sub:             result = a1 - a2;             break;         case VKOCalcOperation::multiply:             result = a1 * a2;             break;         case VKOCalcOperation::divide:             result = a1 / a2;             break;     }     response.parmResult(result);     return response; }
Contract:
[DataContractAttribute("Calc")] class VKOCalcContract {     int                 arg1;     int                 arg2;     VKOCalcOperation    operation;     VKOCalcSubContract  subCalc;     List                subList; }
[DataMemberAttribute("arg1")] public int parmArg1(int _arg1 = arg1) {     arg1 = _arg1;     return arg1; }
[DataMemberAttribute("arg2")] public int parmArg2(int _arg2 = arg2) {     arg2 = _arg2;     return arg2; }
[DataMemberAttribute("operation")] public int parmOperation(int _operation = operation) {     operation = _operation;     return operation; }
//This parm is just for demonstration on how you can use nested contracts and lists [DataMemberAttribute("subCalc")] public VKOCalcSubContract parmSubCalc(VKOCalcSubContract _subCalc = subCalc) {     subCalc = _subCalc;     return subCalc; }
Sub contract:
[DataContractAttribute("SubCalc")] class VKOCalcSubContract {     int a; }
[DataMemberAttribute("a")] public int parmA(int _a = a) {     a = _a;     return a; }
Response contract:
[DataContractAttribute] class VKOCalcResponseContract {     real result; }
[DataMemberAttribute("result")] public real parmResult(real _result = result) {     result = _result;     return result; }
Additionally you will need to
- create service pointing to the service class with service operation pointing to the calc method of service class.
- create service group holding created service
- deploy service group
- create inbound endpoint
  - uncheck transformation
  - Adapter: HTTP
  - Expose service operations: created service
  - Security Restrict users: your account
  - Security Allow trusted intermediary to impersonate: your account

To test use SoapUI or Postman.
SoapUI:
- create project using wsdl URL (this might require to enable Anonymous Authentication at IIS and then iisreset cmd, later can be disabled)
- Authorization NTLM

Request example:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://schemas.microsoft.com/dynamics/2010/01/datacontracts" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:tem="http://tempuri.org" xmlns:dyn="http://schemas.datacontract.org/2004/07/Dynamics.Ax.Application">
   <soapenv:Header>
   </soapenv:Header>
   <soapenv:Body>
      <tem:VKOCalcServiceCalcRequest>
         <!--Optional:-->
         <tem:_calcContract>
            <!--Optional:-->
            <dyn:arg1>3</dyn:arg1>
            <!--Optional:-->
            <dyn:arg2>4</dyn:arg2>
            <!--Optional:-->
            <dyn:operation>0</dyn:operation>
         </tem:_calcContract>
      </tem:VKOCalcServiceCalcRequest>
   </soapenv:Body>
</soapenv:Envelope>
Response example:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <VKOCalcServiceCalcResponse xmlns="http://tempuri.org">
         <response xmlns:b="http://schemas.datacontract.org/2004/07/Dynamics.Ax.Application" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <b:result>7</b:result>
         </response>
      </VKOCalcServiceCalcResponse>
   </s:Body>
</s:Envelope>

Links:
Custom service development (russian): https://www.youtube.com/watch?v=XiEKtCfOgcs
Postman and SOAP: https://www.youtube.com/watch?v=DR3EEhjn2OI
D365 custom service example: https://daxonline.org/1580-simple-custom-service-implementation-example-d365.html

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags