ASMX Web Services: Read only property is not exposed

Posted: November 21, 2012 in .Net/C#
Tags: ,

I was implementing a web service for our third party client to talk with, but there is one simple property wasn’t exposed to the client side.

After some investigation, I found that it’s because this property is read-only.

I found this Microsoft article, PRB: Read-Only Properties Cannot Be Exposed by XML Web Services. It provides two simple workarounds, either add an empty setter or throw an exception inside the setter.

pubilc string ReadOnlyProperty{
      return <the value behind>;
      throw new Exception("ReadOnlyProperty is read-only.");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s