web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

class accessor methods x++

(3) ShareShare
ReportReport
Posted on by 230
Hi,

I think by default class is internal (if we don't define it like code below) and variables are protected by default
[DataContractAttribute]
class CustContract
{
    AccountNum         custAccount;

    [DataMember("custAccount")]
    public AccountNum parmCustAccount(AccountNum _custAccount = custAccount)
    {
        custAccount= _custAccount;
        return custAccount;
    }
}

So for custom services:

1. Is it better to make class public instead?
2. Is it better make variables private instead of protected?
3. For the data member name, is it better to make it capital letter or small letter? i mean custAccount or CustAccount?  i think maybe small letter to match json style?
Categories:
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,720 Most Valuable Professional on at
    If a class doesn't have an access modifier, it's public, not internal. But if you create a new class in Visual Studio, it has the internal access modified by default; it's not created without any modifier.
     
    The answer to "Is it better make variables private instead of protected?" is "it depends". Both have their purpose and what's better (or the only option) depends on the particular situation. For example, if you want child classes access the variable, it must be protected, not public. If you don't want your service class to allow inheritance, set it as final and then there is no point of making fields protected. And so on.
     
    I usually don't override the name in DataMember attribute, but if I do, I use a capital first letter. But what's better depends on the particular scenario, as always.
  • CU22120935-0 Profile Picture
    230 on at
    Hi Martin,


    Thank you.

    for DataMember name, if we don't override the name, then in json, the field will be called parmCustAccount when filling it in postman (i think it's better for the name to appear without the word parm) And we if put it capital letter or small letter, i think postman will allows us to put it either capital or small. But json in general begins with small letter, that's why i thought we should make the name start with small letter (Even though i do also prefer capital letter)

     
  • Martin Dráb Profile Picture
    239,720 Most Valuable Professional on at
    I don't say that you shouldn't use lowercase. But the whole argument about JSON is not applicable if you access the service through the SOAP endpoint. You may want to optimize the letter case for the real thing (e.g. C# code consuming the web service) rather than Postman. Also, most data contracts are used for other things than custom service (mainly SysOperation framework, including reports). As I said, what's the best implementation always depends on what you're doing.
  • CU22120935-0 Profile Picture
    230 on at
    so if it's used by both json and soap, what to do?

    which one of those three to choose?
        [DataMember("custAccount")]
        public AccountNum parmCustAccount(AccountNum _custAccount = custAccount)
        {
            custAccount= _custAccount;
            return custAccount;
        }
    
        [DataMember("CustAccount")]
        public AccountNum parmCustAccount(AccountNum _custAccount = custAccount)
        {
            custAccount= _custAccount;
            return custAccount;
        }
    
       [DataMember]
        public AccountNum parmCustAccount(AccountNum _custAccount = custAccount)
        {
            custAccount= _custAccount;
            return custAccount;
        }
  • Martin Dráb Profile Picture
    239,720 Most Valuable Professional on at
    The one that works best for your scenario. You said it was the first one. Just don't forget that Postman is just a test tool; make sure you take the real scenario (how the web service will be used) into account.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 565 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 487 Super User 2026 Season 1

#3
Subra Profile Picture

Subra 413

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans