Dear all,
I have custom service which return list of data. But while its returning the data the list class also returning all parameter methods which is associated with service/List class. Please how can I fix this issue the list parameters that I don't required in json format. And I can't remove the parameter from class while its using for other service methods in same service class.
[DataContractAttribute] class salesProj { YearBase years; Name salesMan; ProjId projId; InvoiceDate invoiceDate; AmountMST invoiceAmountmst; } [ DataMemberAttribute('Year')] public YearBase parmInvoiceYear(YearBase _invoiceyear = years) { years = _invoiceyear; return years; } [ DataMemberAttribute('InvoiceAmount')] public AmountMST parmInvoiceAmount(AmountMST _invoiceAmount = invoiceAmountmst) { invoiceAmountmst = _invoiceAmount; return invoiceAmountmst; } [ DataMemberAttribute('ProjId')] public ProjId parmProjId(ProjId _projectId = projId) { projId = _projectId; return projId; } [ DataMemberAttribute('Salesman')] public Name parmSalesman(Name _salesMan = salesMan) { salesMan = _salesMan; return salesMan; } [SysEntryPointAttribute(true),AifCollectionTypeAttribute("return" , Types::Class, classStr(salesProj))] public List getprojTotalCurrentYearAmount() { salesProj salesClassObj; List saleslist = new List(Types::Class); salesClassObj = new salesProj(); salesClassObj.parmInvoiceYear(2021); salesClassObj.parmInvoiceAmount(this.currentYearProjSales()); saleslist.addEnd(salesClassObj); return saleslist; } C# Web api [HttpGet] [Route("api/getProjSales")] public HttpResponseMessage GetProjSales() { CallContext callContext = new CallContext(); callContext.Company = "ENPR"; callContext.Language = "en-us"; testcustomerClient client = new testcustomerClient(); custClass[] salesProj = client.getProjSales(callContext); List saleslist = new List(); foreach (var item in salesProj) { saleslist.Add(item); } return Request.CreateResponse(HttpStatusCode.OK, saleslist); } //Json formart [{"InvoiceAmount":25072.43,"InvoiceDate":"1900-01-01T12:00:00","ProjId":"","Salesman":"","Year":2021}] How can I remove "InvoiceDate":"1900-01-01T12:00:00","ProjId":"","Salesman":"", above format while list class from AX its returning all parameters.
I manage by creating new contract class with single service. Once I called service operations its referring now new contract classes.
Thank you.
You need do decide what you want. If you insist on having a single operation returning everything, then don't complain that it does return everything.
But it doesn't look like a good design. Why can't you create a single service with three operations, one of projects, one for customers and one for sales?
Also, consider if you can't meet your requirements with standard services, namely the query service or document services.
Why do you think that creating a new contact class and modifying code of a single service operation requires creating a completely new service and even a new service group?
If I create new data contract again I have to create service nodes and service group deployement. That means for every new service operatione Data contract and new service URL. This way it takes time. I need all operations projects, customers, sales etc all in one service url. But once I return data it should be related to that parameters only. Not all.
You can create a new data contract class with the data you want and return this new data contract instead of the one that you're using at the moment.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156