How to stop a setter exposed to web services?

I want to have a class

public class Apple
{
    public string Size { get; set;}
    public string Colour { get; set;}
    public string Shape { get; set;}
    public int appleId { get; set;}
}

I want to show that through web services, using some web methods like this,

public void AddApple(Apple apple)
{
}

public Apple GetApple(int appleId)
{
}

Therefore, when I add a service link in visual studio to this web service, I get client proxy objects for me that allow me to create Apple on the client side and send them through the web service.

Is there a way to make one of these properties read-only on the client side? I need setters there so that I can set values ​​on the server side, but I want to control what data they can update on the client side.

Any ideas?

, , , , . , .

+3
3

, -, . , , ( , ). .

: - - (, Apple1), - - , Apple2. , Apple2 , , -, . Apple1, Apple2, , , , , / . , AppleFull, Apple1 Apple2.

+3

, , , , simillar, -

WCF Value Driven Driven

+1

Another way to achieve this is to share an assembly containing the Apple class (but not the server component) between the server and the client. Make internal setters and mark the server-side builds as friends using the InternalsVisibleTo attribute.

This will allow the server to use setters, but not the client.

0
source

Source: https://habr.com/ru/post/1763942/


All Articles