PDA

View Full Version : strange compile error for consumer of web service


chump2877
09-25-2007, 05:48 PM
The problem: I have a WebMethod that is returning (or supposed to return) a DataSet to my consuming application. But I'm getting a wierd compile error.

The web service (StudentTableService.asmx):

using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using Tric.StudentRegistration.DataAccess;

namespace StudentRegistrationServices
{
/// <summary>
/// Summary description for StudentTableService
/// </summary>
[WebService(Namespace = "http://StudentTableService.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class StudentTableService : System.Web.Services.WebService
{
[WebMethod]
public DataSet GetStudents()
{
TableDataAccess tda = new TableDataAccess();
DataTable dataTable = tda.GetStudents();
return dataTable.DataSet;
}
[WebMethod]
public void UpdateStudents(DataSet dataSet)
{
TableDataAccess tda = new TableDataAccess();
tda.UpdateStudents(dataSet.Tables["Student"]);
}
}
}


The relevant consumer app code:

private void RenderGridView()
{
StudentRegistrationServices.StudentTableService webService = new StudentRegistrationServices.StudentTableService();
DataSet dataSet = webService.GetStudents();
DataTable studentDataTable = dataSet.Tables["Student"];
DataView dataView = SortDataTable(studentDataTable);
// Bind the sorted DataView object to the GridView
GridView1.DataSource = dataView;
GridView1.DataBind();
Session["DataTable"] = studentDataTable;
}


This line of code in the consuming app:
DataSet dataSet = webService.GetStudents();

...produces the following error:
Error 1 Cannot implicitly convert type 'StudentWeb.StudentRegistrationServices.GetStudentsResponseGetStudentsResult' to 'System.Data.DataSet'

This is the ONLY compile error that I am receiving.

I have been stuck on this for days. :(

Help is appreciated. Thanks.

nikkiH
09-25-2007, 07:35 PM
Web services communicate via xml, as I'm sure you know; you probably shouldn't use .NET types like DataSet directly, at least if the consumer of the service may not be a .NET application. If you decide you want to do that anyway because you control the consumers, the issue may be in your wsdl.
Check out this article and see if it helps.
http://www.theserverside.net/tt/articles/showarticle.tss?id=Top5WSMistakes

nikkiH
09-25-2007, 07:51 PM
Oh, and are you using typed datasets?
See this thread about importing them.
http://www.csharphelp.com/board2/read.html?f=1&i=42029&t=42029

chump2877
09-25-2007, 09:55 PM
Web services communicate via xml, as I'm sure you know; you probably shouldn't use .NET types like DataSet directly, at least if the consumer of the service may not be a .NET application. If you decide you want to do that anyway because you control the consumers, the issue may be in your wsdl.
Check out this article and see if it helps.
http://www.theserverside.net/tt/articles/showarticle.tss?id=Top5WSMistakes

That is a great freakin article, Nikki....:thumbsup:

If I don;t use the DataSet type to transmit data to and from my web service, then what data types do you recommend (given that the data is being sent to and from MS SQL server)?

I briefly skimmed: http://www.w3.org/TR/xmlschema-2/. But that's a lot of reading....Nonetheless, are we basically referring to ASP.NET's primitive types for transmitting data to and from web services (regarding best practices for .NET web service development)? And perhaps also user-defined classes and structs that rely on primitive types?

Would converting the DataSet to and from XML be a viable solution -- so that the web service WebMethods only return XML/string types and only accept XML/string parameters? This forum post describes such a solution, converting DataSet types to and from XML strings: http://www.thescripts.com/forum/thread376476.html

What do you think? Thanks...


Edit: Also, and perhaps foremost, would such a solution get rid of my compilation error, do you think?

nikkiH
09-26-2007, 03:29 PM
I would go for a business object that was serialized to XML if I was thinking the consumer would be another business, but for just going to and from the database, you're probably fine. You know how everyone has opinions on the "right" way to do things and all. :D

The compile error might actually just be a bug, as I saw some hits on that when I searched for it. Which version of .NET and Studio are you using? 3.0 is still a bit buggy as far as the framework, and the new Studio Express beta has some odd little issues, too.

How did you import the service in order to call it? Did you add a web reference and point to the WSDL? If so, that is what VS is using to determine the data type that it needs to match, so you may have an issue with the WSDL.
Can you post that?

chump2877
09-27-2007, 01:20 AM
I would go for a business object that was serialized to XML if I was thinking the consumer would be another business, but for just going to and from the database, you're probably fine. You know how everyone has opinions on the "right" way to do things and all. :D


"A business object that was serialized to XML" seems like a good idea. I tend to agree with you on avoiding .NET specific types in web services, except when you control the consumers and the service.


The compile error might actually just be a bug, as I saw some hits on that when I searched for it. Which version of .NET and Studio are you using? 3.0 is still a bit buggy as far as the framework, and the new Studio Express beta has some odd little issues, too.


I'm using VS2005 Professional edition and .NET 2.0...


How did you import the service in order to call it? Did you add a web reference and point to the WSDL?


I solved the compilation error, i guess....I'm testing the web service and a "dummy" consuming app locally in VS2005's development server...The web reference in the consumer points to the web service...Both service and consumer are in the same VS2005 solution file, for now....I think the error I was getting was VS2005 complaining about this goofy setup for a web service and its consuming application, and possibly the fact that I'm not using IIS to test it...To fix the problem, I simply recreated the web reference in the consuming app (which I could have sworn I had done earlier, but whatever)....

I expect that in a real-world application of this web service, I would not have this problem...

Thanks for your help, as usual...:)

nikkiH
09-27-2007, 03:23 PM
LOL @ complaining about the goofy setup. :D

You're welcome, though also as usual, you solved it. I just helped you think it through.