BUG: A Typed DataSet That Imports a Secondary Schema Cannot be Used As a Method Parameter or As a Return Type with ASP.NET Web Services (317340)
The information in this article applies to:
- Microsoft Web Services (included with the .NET Framework)
This article was previously published under Q317340 SYMPTOMSYou cannot create a Web service proxy when the Typed DataSet
that imports a secondary schema is used as a parameter or as a return type from
the
WebMethod. If you try to do this, the following symptoms may occur:
CAUSE When you create the Web service proxy that uses Typed
DataSet, the Typed DataSet does not correctly import secondary schemas. Instead
of using the expected secondary schema, the returned schema imports a schema
with an arbitrary name such as _app1.xsd. Because of an incorrect secondary
schema name, the tools such as WSDL.exe or Microsoft Visual Studio .NET cannot
correctly create a proxy for the Web service. Also, the returned XML cannot be
serialized back to a corresponding Typed DataSet instance. If you try to do
this, the result is an XmlSchemaException.WORKAROUND To work around this problem, return the Typed DataSet that
you want as an XmlElement in your WebMethod. In your client, you can explicitly load the returned XML to an
instance of the Typed DataSet that you want. The following code is an example
for WebMethod: Visual Basic .NET <WebMethod()> Public Function GetTypedDataSet() As System.Xml.XmlElement
' Create an instance of Typed DataSet.
Dim myDs As MyTypedDataSet = New MyTypedDataSet()
' Populate the DataSet with the Data.
Dim myCn As New System.Data.SqlClient.SqlConnection("Persist Security Info=False;User ID=<username>;Password=<strong password>;Initial Catalog=pubs;Data Source=SQLServer;Packet Size=4096")
myCn.Open()
Dim myDa As New System.Data.SqlClient.SqlDataAdapter("Select * from Employee", myCn)
myDa.Fill(myDs, myDs.Tables(1).TableName)
' Return the DataSet as an XmlElement.
Dim xdd As System.Xml.XmlDataDocument = New System.Xml.XmlDataDocument(myDs)
Dim docElem As System.Xml.XmlElement = xdd.DocumentElement
Return docElem
End Function Visual C# .NET [WebMethod]
public System.Xml.XmlElement GetTypedDataSet ()
{
// Create an instance of Typed DataSet.
MyTypedDataSet myDs = new MyTypedDataSet ();
// Add some data to the DataSet.
System.Data.SqlClient.SqlConnection myCn =new System.Data.SqlClient.SqlConnection("Persist Security Info=False;User ID=<username>;Password=<password>;Initial Catalog=pubs;Data Source=SQLServer;Packet Size=4096");
myCn.Open();
System.Data.SqlClient.SqlDataAdapter myDa = new System.Data.SqlClient.SqlDataAdapter("Select * from Employee", myCn);
myDa.Fill(myDs, myDs.Tables[1].TableName);
// Return the DataSet as an XmlElement.
System.Xml.XmlDataDocument xdd = new System.Xml.XmlDataDocument (myDs);
System.Xml.XmlElement docElem = xdd.DocumentElement;
return docElem ;
} Modify the SQL connection string to access data from Microsoft SQL
Server. The following code shows the sample client that calls the WebMethod: Visual Basic .NET Public Sub GetData()
' Create an instance of Typed DataSet.
Dim ds As MyTypedDataSet = New MyTypedDataSet()
' Create an instance of Web service proxy.
Dim WebProxy As MyWebServiceProxy = New MyWebServiceProxy()
' Get the data from Webservice
Dim elem As XmlElement = WebProxy.GetTypedDataSet()
' Load the XML to the Typed DataSet that you want.
Dim nodeReader As XmlNodeReader = New XmlNodeReader(elem)
ds.ReadXml(nodeReader, XmlReadMode.Auto)
' Use Typed DataSet as you would typically do.
End Sub Visual C# .NET
public void GetData()
{
// Create an instance of Typed DataSet.
MyTypedDataSet ds = new MyTypedDataSet ();
// Create an instance of Web service proxy.
MyWebServiceProxy WebProxy = new MyWebServiceProxy () ;
// Get the data from Webservice.
XmlElement elem = WebProxy.GetTypedDataSet () ;
// Load the XML to the Typed DataSet that you want.
XmlNodeReader nodeReader = new XmlNodeReader (elem) ;
ds.ReadXml (nodeReader, XmlReadMode.Auto) ;
// Use Typed DataSet as you would typically do.
}
STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
REFERENCES For additional information about creating Typed
DataSet, click the following article numbers to view the 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
Modification Type: | Major | Last Reviewed: | 11/7/2003 |
---|
Keywords: | kbWebServices kbSystemData kbSqlClient kbDataAdapter kberrmsg kbbug KB317340 kbAudDeveloper |
---|
|