Microsoft KB Archive/317270

= PRB: Read-Only and Write-Only Class Properties Not Accessible from a Web Service =

Article ID: 317270

Article Last Modified on 2/11/2004

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft .NET Framework 1.1
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft .NET Framework 1.0

-



This article was previously published under Q317270



SYMPTOMS
When you try to access read-only and write-only properties of a class that you obtain from a Web service, you cannot view the properties.



CAUSE
XML serialization and ASP.NET Web services do not support read-only and write-only properties. Information about these properties is not published in Web Services Description Language (WSDL) documentation.



WORKAROUND
To access the properties, use the Web methods in the WebService class. To do this, follow these steps:   In the Service1.asmx.vb file, paste the following Web methods after the #Region &quot; Web Services Designer Generated Code&quot; block:  Public Function GetValue1 As Integer Dim c1 As New Class1 GetValue1 = c1.Value1 End Function

 Public Function SetValue2(ByVal x As Integer) As Boolean Dim c2 As New Class1 c2.Value2 = x       Return True End Function   In the WebForm1.aspx.vb file, instead of code that tries to directly access the properties, paste the following code in the Page_Load method: data=&quot;Dim i as Integer i = myVar2.GetValue1 myVar2.SetValue2(5)&quot;?>Dim myvar As New localhost.Service1 Dim myInt As Int32 myInt = myvar.GetValue1 myvar.SetValue2(100) 



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Use Visual Basic to create a new Web service project.</li>  In Service.asmx.vb, paste the following code in the Service1 class: <WebMethod> Public Function GetObject As Class1 GetObject = New Class1 End Function </li>  Paste the following class after the Service1 class: Public Class Class1 Private mVal1 As Integer Private mVal2 As Integer

Public ReadOnly Property Value1 As Integer Get Value1 = mVal1 End Get End Property

Public WriteOnly Property Value2 As Integer Set(ByVal Value As Integer) mVal2 = Value End Set End Property End Class </li> Build the Web service.</li> Create a new Web application.</li> Add a Web reference to the Service1.asmx Web service. The default location for this file is the http://localhost/WebService1 folder.</li>  Declare an instance of localhost.Class1, and then attempt to access the Value1 and Value2 properties in the Page_Load method of Webform1.aspx, as follows: Dim myvar as localhost.Class1 Dim myInt as Int32

myInt = myvar.Value1 myvar.Value2 = 100 </li></ol>

Keywords: kbprb KB317270

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.