Sir
now I use dataset to do web services, but when I reture object, it's dataset object.
My question is how to serializer dataset? because if my customers devlope non dotnet platform,for example Java,maybe he can't read dataset.Can you help me how to do?
I search information several days but I don't know how to do.
Thanks a lot!!
Loading
andyPosted Apr 14, 2011, 9:16 PM
Suthish NairPosted Apr 14, 2011, 7:49 AM
Mahesh ChandPosted Apr 13, 2011, 9:50 PM
string ThisIsYourWebMethodKeepWhateverElseYouHaveHereJustReplaceDataSetWithString()
{
// Put all your code that gets data from the database in a DataSet
// Let's say, your data is coming in a DataSet object called "myDataSet"
return myDataSet.GetXml()
}
Now this method will return a string that is filled with XML. Your non-.NET client has to read this string in an XmlNode or XmlDocument object.
andyPosted Apr 13, 2011, 9:25 PM
Andrew FensterPosted Apr 13, 2011, 1:48 PM
The WS- standards are a bunch of industry standards for web services. They set standards so that I can write a web service in .Net and you can call it from a Java application, and everything will work. They include:
WS-Reliability
WS-BaseFaults
WS-Interoperability
WS-Transfer
WS-AtomicTransaction
etc. WCF implements most or all of them. (I don't really know exactly how close to the standards it comes.)
All that matters here is that the standards define what to do if you want to make a web service that can be called by other languages. The main thing is to use common data types: XML, integers, decimals, strings, booleans, dates, etc. As long as you stick to those, everything will be fine.
Sam HobbsPosted Apr 13, 2011, 1:08 PM
Obviously Andrew does not like XML. There are many options for processing XML; you can create XML using classes that make it easier than generating XML strings directly as in Andrew's sample. I am not sure I know what Andrew means by "WS-*" standards but as best as I can tell it uses XML about as much as our bodies are composed of water. This web site seems to have many articles about the "WS-*" standards (such as Chapter 32: Web Service Standards and Extensions) so you can get many answers by looking at many of the articles in this web site.
Andrew FensterPosted Apr 13, 2011, 12:22 PM
You can either build an XML string:
string myXml = "
foreach (DataRow row in myTable.Rows)
{
myXml += "
myXml += "
myXml += "
myXml += "
etc.
}
string myXml += "
Then you return this XML string as the return value from your web service. It would look like this:
[etc. more customers here]
As an alternative, you can create a class to hold the data:
class Customer
{
string name;
int customerID;
}
The members of the class must be strings, numbers, Dates, DateTimes, booleans.
Now, instead of building XML, you build an array of Customer objects. Your return value is the array. Either way, your Java, PHP or other common development languages will have no problem. There are a series of standards (the so called "WS-*" standards), and you have complied with them.
andyPosted Apr 13, 2011, 4:07 AM
Sam HobbsPosted Apr 12, 2011, 10:06 PM
I think it will help you if you determine what is the best format for the other programs. You say you want to ensure they can use the data and the best way to do that is to find out what they can use.
The best choice is XML. XML is highly standard and can be read by most languages and such, especially Java. Unless you learn that there is something better to use for the other programs, use XML. XML can be understood by people better than most other formats without other software. Sometimes text formats such as CSV are more convenient than XML but usually XML would be easier. There are more software tools for using XML than nearly every other format in common use, other than text formats such as CSV. XML is an extremely common format for Java.
Andrew FensterPosted Apr 12, 2011, 12:20 PM
A DataSet is a Microsoft data type. If you are making web services that will be called by non .Net clients, you should not pass them .Net data types. Numbers, strings, dates, arrays, etc. are fine. DataSets, DataTables, Lists, etc. are not good. They do not comply with the WS-* web service standards.
It's true that a DataSet can be serialized as an XML. However the non .Net programmers will have a very hard time converting the XML into something that they can use. The XML is generated automatically, and it's not user friendly. It was not designed to be read by humans. They will have to write a lot of custom code to parse the XML. They won't like that.
Without too much effort you can create and transmit something that would be much easier for your non .Net clients. You should take the data in your DataSet and create an array of objects that don't use Microsoft specific data types, or you can build an XML string.
Finally, if you're making services to be called by non .Net clients, you should probably use WCF. It's standards-compliant. It was made to make web services that anyone can call, even non .Net clients. However, it won't easily let you send a DataSet.
andyPosted Apr 12, 2011, 12:03 PM
Mahesh ChandPosted Apr 12, 2011, 12:58 AM