Microsoft KB Archive/811588

= Compiler errors when .NET Compact Framework project uses an XML Web service that exposes typed DataSet =

Article ID: 811588

Article Last Modified on 2/28/2006

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Web Services Enhancements for Microsoft .NET 2.0
 * Microsoft Web Services Enhancements for Microsoft .NET 1.1
 * Microsoft .NET Compact Framework

-



SYMPTOMS
In Microsoft Visual Studio .NET 2003 or in Microsoft Visual Studio 2005, when you build a .NET Compact Framework project that uses an XML Web service that exposes a typed DataSet as a WebMethod, several compiler errors occur. For example, you receive the following error messages:

Type 'Serializable' is not defined.

Type 'System.ComponentModel.ToolboxItem' is not defined.

Type 'StrongTypingException' is not defined.



CAUSE
When you use Add Web Reference in a Smart Device application project to add a Web reference to a Web service that exposes a typed DataSet, Visual Studio .NET or Visual Studio 2005 binds to the service, and then generates a proxy class for the Web service. When you try to compile the application, several compiler errors are generated. The errors occur because Visual Studio .NET or Visual Studio 2005 inserts many serialization attributes in the proxy file that the .NET Compact Framework does not support.



WORKAROUND
To work around this problem, use either of the following methods:   In your Web service, instead of using Typed DataSet, use the System.Data.DataSet class. You can still handle the data by using a Typed DataSet on the Web server. Before returning the data, type cast the data to DataSet in the Web service method, and then return the data to the client, as in the following sample code:

Visual Basic .NET or Visual Basic 2005 sample code  _ Public Function GetDataSet As DataSet ' DataSet1 is a typed DataSet. Dim objTypedDS As New Dataset1

' Create a DataSet. Dim objDS As DataSet objDS = objTypedDS Return objDS End Function Visual C# .NET or Visual C# 2005 sample code [WebMethod] public DataSet GetDataSet {     // DataSet1 is a typed DataSet. DataSet1 objTypedDS = new DataSet1;

// Create a DataSet. DataSet objDS; objDS = (DataSet1)objTypedDS; return objDS; }  Manually comment out the serialization attributes in the generated client proxy class. This allows the .NET Compact Framework project to gain access to the DataSet in a typed manner. However, every time the Web reference is updated, you must modify all the affected changes because Visual Studio .NET overwrites the proxy class.



STATUS
This behavior is by design.



Steps to reproduce the behavior
 Create a new ASP.NET Web Service project by using Visual Basic .NET, Visual Basic 2005, Visual C# 2005, or Visual C# .NET. By default, Service1.asmx is created. Create a typed DataSet named DataSet1.

For more information about how to create a typed DataSet, see the following articles in the Microsoft Knowledge Base:

315678 How to create and use a typed DataSet by using Visual Basic .NET

320714 How to create and use a typed DataSet by using Visual C# .NET

</li> Right-click Service1.asmx, and then click View Code.</li>  Add the following sample code to Service1:

Visual Basic .NET or Visual Basic 2005 sample code <WebMethod> _ Public Function GetDataSet As Dataset1 Dim objTypedDS As New Dataset1 '       ' Write code to process the data by using Typed DataSet. '       Return objTypedDS End Function

Visual C# .NET or Visual C# 2005 sample code [WebMethod] public DataSet1 GetDataSet {        DataSet1 objTypedDS = new DataSet1; //        // Write code to process the data by using Typed DataSet. //        return objTypedDS; } </li> On the Debug menu, click Start. Copy the URL for the Web service that appears in the browser. Close the browser.</li> Create a new Smart Device Windows Application by using Visual C#, Visual Basic .NET, or Visual Basic 2005.</li> In Solution Explorer, right-click References, and then click Add Web Reference.</li> In the URL text box, paste the URL that you copied in step 5, and then press ENTER.</li> Click Add Reference to create and then add the proxy file for the Web service.</li> On the Build menu, click Build Solution.</li></ol>

<div class="references_section">