I’m having a problem with a web service returning a typed dataset when there are row errors, and I’m hoping someone out there can shed some light on the subject.
The problem only happens in .NET 1.1. The same code works fine in .NET 1.0 (changing the runtime version through VS.NET toggles from working/1.0 to not-working/1.1).
In a nutshell, when a typed dataset with a row error is returned from a web service, .NET 1.1 can’t deserialize the dataset. It fails with an InvalidOperationException in the XmlSerializer, with the error ‘There is an error in XML document’. It looks to me like the XmlSerializationReader is reading up to the EOF marker instead of stopping at the end of the current tag, but that’s just a guess based on EOF being true when the exception is thrown.
The demo of the problem is a bit convoluted to set up, since it only happens when using a web service, not regular serialization, so I’ll summarize the code here and point you to the project file downloads.
First of all, the web service. This is a trivial one – first a new web service project is created, then add the following web method:
[WebMethod]
public DataSet BreakDataSet (DataSet dsDataSet)
{
dsDataSet.Tables[0].Rows[0].RowError = "Something bad happened.";
return dsDataSet;
}The problem only shows itself when there are row errors in the returned dataset, so all the code does is add a row error message to the first row of the first table.
The client test program is a bit longer, but it’s still pretty trivial. It has a typed dataset, with one table ‘TestTable’ which has one column ‘TestColumn’. The client program just instantiates one of these typed datasets, creates a row, and calls the above web method.
TestData tdOriginal = new TestData (); TestData.TestTableRow trRow = tdOriginal.TestTable.NewTestTableRow (); trRow.TestColumn = "Hello world"; tdOriginal.TestTable.AddTestTableRow (trRow);
TestWS.Test wsTester = new TestWS.Test (); DataSet dsResult = wsTester.BreakDataSet (tdOriginal);
And that’s when it all breaks. I get the exception:
InvalidOperationException There is an error in XML document (1, 1508). at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle) at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader) at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at SerialProblem.TestWS.Test.BreakDataSet(DataSet dsDataSet) in C:\Documents and Settings\Geoff\My Documents\Visual Studio Projects\SerialProblem\Web References\TestWS\Reference.cs:line 37 at SerialProblem.SerialProblem.butTest_Click(Object sender, EventArgs e) in c:\documents and settings\geoff\my documents\visual studio projects\serialproblem\serialproblem.cs:line 119
The inner exception is: NullReferenceException Object reference not set to an instance of an object. at System.Xml.Serialization.XmlSerializationReader.UnknownNode(XmlNode unknownNode, Object o) at System.Xml.Serialization.XmlSerializationReader.UnknownNode(Object o) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read3_BreakDataSetResponse() in c:\Documents and Settings\Geoff\Local Settings\Temp\8pryukh9.0.cs:line 117
The interesting thing is, you can set the client application to use .NET v1.0 and the problem goes away. (It doesn’t seem to make any difference which runtime is used for the web service.)
The source files for the web service project are temporarily available at:
http://www.opinionatedgeek.com/DotNet/Stuff/SerialProblemWS.zip
The source files for the client app are temporarily available at:
http://www.opinionatedgeek.com/DotNet/Stuff/SerialProblem.zip
The project I’m working on (nothing to do with OpinionatedGeek.com, BTW) is currently .NET 1.0, and it makes heavy use of web services and datasets, so this problem is going to really hurt. It’s already a problem when calling our web services from SharePoint 2003, which requires .NET 1.1 – the only error message we can show at the minute is a general one, because the actual error message is in the row error and our code never gets to see it.
If anyone has any suggestions or ideas, I’d love to hear them.
Many thanks,
Geoff
=================================== This list is hosted by DevelopMentor® http://www.develop.com NEW! ASP.NET courses you may be interested in:
2 Days of ASP.NET, 29 Sept 2003, in Redmond http://www.develop.com/courses/2daspdotnet
Guerrilla ASP.NET, 13 Oct 2003, in Boston http://www.develop.com/courses/gaspdotnet
View archives and manage your subscription(s) at http://discuss.develop.com
