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



The information in this article applies to:

  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Web Services (included with the .NET Framework) 1.0
  • Microsoft Web Services (included with the .NET Framework 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
       <WebMethod()> _
       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.

MORE INFORMATION

Steps to reproduce the behavior

  1. 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.
  2. 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

  3. Right-click Service1.asmx, and then click View Code.
  4. 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;
          }
  5. On the Debug menu, click Start. Copy the URL for the Web service that appears in the browser. Close the browser.
  6. Create a new Smart Device Windows Application by using Visual C#, Visual Basic .NET, or Visual Basic 2005.
  7. In Solution Explorer, right-click References, and then click Add Web Reference.
  8. In the URL text box, paste the URL that you copied in step 5, and then press ENTER.
  9. Click Add Reference to create and then add the proxy file for the Web service.
  10. On the Build menu, click Build Solution.

REFERENCES

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

313486 Roadmap for Visual Database Tools and typed DataSets


Modification Type:MajorLast Reviewed:2/28/2006
Keywords:kbvs2005applies kbvs2005swept kbcode kbNameSpace kbClient kbprb kberrmsg KB811588 kbAudDeveloper