Can I create read-only items in SOAP web services?

I have a class with a given read-only. In my code, I define this as a property with a getter only.

I want so that I can send this object back and forth through a web service. When I call the Get method in the service, it will be populated with the value from the service side. As soon as I define this property, I do not want the web service consumer to be able to set / change this property.

When I add a link to this web service in the project, the object has a property serialized in several ways, depending on how I try to define the object from the service side:

  • internal setter . Creates a property in WSDL. Visual Studio generates a class with a getter and installer for this property.
  • no setter : does not create a property in WSDL. Visual Studio then does not explicitly define this property at all.
  • Public variable public access . Does not create a property in WSDL. Again, Visual Studio will not do anything with this property because it does not know about it.

Allowing the web service consumer to set the value for this property is not harmful. If set, it is ignored on the web service side. I would prefer if the consumer cannot change / set the property to start with.

Is there a way to define a property as read-only? Right now we are using C # /. NET 2.0 for a web service and (at the moment, at least), we control all users of this service, so I can try changing the settings if necessary, but I prefer only changing things on the web -service, not consumers.

+3
source share
3 answers

Caution, I'm a Java guy, so the first part of my answer is about what might be possible in C #.

-, Java , , , . , # , , , .

-, , , - - . - , " ". , WSDL . , . - , API - . WSDL XSD API -, , . - XML, , , ( ) () .

, , , -, , API -, ( ) .

+1

, , , - , - . "" , .

+3

.NET 2.0, . , , IXmlSerializable, ReadXml() WriteXml().

.NET , .

0
source

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


All Articles