//Building & consume Custom service in Dynamics 365 for finance and operations
//Create new project
//Create new class for data contract
[DataContractAttribute]
class SSLBalanceDataContract
{
TransDate transDate;
SSLAccount accountNum;
DataAreaId dataAreaId;
[DataMemberAttribute('DateTransactionDate'),
SysOperationLabelAttribute(literalStr("@SYS11284"))]
public TransDate parmTransDate(TransDate _transDate = transDate)
{
transDate = _transDate;
return transDate;
}
[DataMemberAttribute('Company'),
SysOperationLabelAttribute(literalStr("@SYS11284"))]
public DataAreaId parmDataAreaId(DataAreaId _dataAreaId =dataAreaId)
{
dataAreaId = _dataAreaId;
return dataAreaId;
}
[DataMemberAttribute('SSLAccount'),
SysOperationLabelAttribute(literalStr("Account number"))]
public SSLAccount parmSSLAccount(SSLAccount _accountNum = accountNum)
{
accountNum = _accountNum;
return accountNum;
}
}
//Create new class for service operations
class SSLBalanceService
{
[AifCollectionType('return', Types::Real,extendedTypeStr(Amount))]
public Amount processData(SSLBalanceDataContract _SSLBalanceDataContract)
{
QueryRun queryRun;
SSLTable SSLTableget;
Amount balance;
System.Exception ex;
try
{
if(_SSLBalanceDataContract.parmDataAreaId())
{
changecompany(_SSLBalanceDataContract.parmDataAreaId())
{
var query = new Query();
var qbds = query.addDataSource(tableNum(SSLTable));
qbds.addRange(fieldNum(SSLTable,SSLAccount)).value(_SSLBalanceDataContract.parmSSLAccount());
queryRun = new queryRun(query);
while(queryRun.next())
{
SSLTableget = queryRun.get(tableNum(SSLTable));
balance = SSLTableget.balanceCur();
}
}
}
}
catch (Exception::CLRError)
{
ex = ClrInterop::getLastException();
if (ex != null)
{
ex = ex.get_InnerException();
if (ex != null)
{
error(ex.ToString());
}
}
}
return balance;
}
}
//Create new service object named as SSLBalanceService and set the following properties on it
Class SSLBalanceService
External name SSLBalanceService
//Right-click on the Service Operations node under our service
SSLBalanceService , select new service operations and set the
following properties:
Method processData
Name processData
//Create a new object under the Service groups node and mention new name i
Name Service
Service SSLBalanceServiceGrp
//Build the project and, on successful build, our web service is available to communicate AX from external
//Now new web service is deployed on SOAP and JSON endpoints automatically.
//Consuming custom services in SOAP - sample code here
https://github.com/Microsoft/Dynamics-AX-Integration/commit/18006cba62649477c2fbe7fb691c263207253be5
//Create new project
//Create new class for data contract
[DataContractAttribute]
class SSLBalanceDataContract
{
TransDate transDate;
SSLAccount accountNum;
DataAreaId dataAreaId;
[DataMemberAttribute('DateTransactionDate'),
SysOperationLabelAttribute(literalStr("@SYS11284"))]
public TransDate parmTransDate(TransDate _transDate = transDate)
{
transDate = _transDate;
return transDate;
}
[DataMemberAttribute('Company'),
SysOperationLabelAttribute(literalStr("@SYS11284"))]
public DataAreaId parmDataAreaId(DataAreaId _dataAreaId =dataAreaId)
{
dataAreaId = _dataAreaId;
return dataAreaId;
}
[DataMemberAttribute('SSLAccount'),
SysOperationLabelAttribute(literalStr("Account number"))]
public SSLAccount parmSSLAccount(SSLAccount _accountNum = accountNum)
{
accountNum = _accountNum;
return accountNum;
}
}
//Create new class for service operations
class SSLBalanceService
{
[AifCollectionType('return', Types::Real,extendedTypeStr(Amount))]
public Amount processData(SSLBalanceDataContract _SSLBalanceDataContract)
{
QueryRun queryRun;
SSLTable SSLTableget;
Amount balance;
System.Exception ex;
try
{
if(_SSLBalanceDataContract.parmDataAreaId())
{
changecompany(_SSLBalanceDataContract.parmDataAreaId())
{
var query = new Query();
var qbds = query.addDataSource(tableNum(SSLTable));
qbds.addRange(fieldNum(SSLTable,SSLAccount)).value(_SSLBalanceDataContract.parmSSLAccount());
queryRun = new queryRun(query);
while(queryRun.next())
{
SSLTableget = queryRun.get(tableNum(SSLTable));
balance = SSLTableget.balanceCur();
}
}
}
}
catch (Exception::CLRError)
{
ex = ClrInterop::getLastException();
if (ex != null)
{
ex = ex.get_InnerException();
if (ex != null)
{
error(ex.ToString());
}
}
}
return balance;
}
}
//Create new service object named as SSLBalanceService and set the following properties on it
Class SSLBalanceService
External name SSLBalanceService
//Right-click on the Service Operations node under our service
SSLBalanceService , select new service operations and set the
following properties:
Method processData
Name processData
//Create a new object under the Service groups node and mention new name i
Name Service
Service SSLBalanceServiceGrp
//Build the project and, on successful build, our web service is available to communicate AX from external
//Now new web service is deployed on SOAP and JSON endpoints automatically.
//Consuming custom services in SOAP - sample code here
https://github.com/Microsoft/Dynamics-AX-Integration/commit/18006cba62649477c2fbe7fb691c263207253be5
No comments:
Post a Comment