Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Webservice To Return Table Data As XML

Status
Not open for further replies.

Skittle

ISP
Sep 10, 2002
1,528
0
0
US
I have succesfully created a webservice that returns a single string parameter. The WSDL and DISCO are of course created for me.

I would now like to enhance the webservice to return the contents of a database table as XML.

I can read data into a dataset no problem.
I can convert the dataset into a string of XML using
MyString = MyDataSet.GetXML.

I'm a bit lost on how to now make sure my WSDL will describe the format of the string XML data I am passing back. It cannot do it automatically ( I assume ) because the XML is generated on the fly outside of Webmethod definition that says I am returning just one string parameter.

Any guidance appreciated.


Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
Skittle..

when you build a webservice.. it does return the data as an xml document :)

typically if you want to be able to preserve the output to an xml file - assuming you are returning a "dataset" object,
just use the dataset.writexml method to save the dataset to disk.

e.g. dim ds as dataset = ws.callsomemethod(12)
ds.writexml("c:\mydataset.xml")
 
OK thanks.

I was a little unsure if I had to worry about producing some sort of schema definition of the format of the data I returned within the web method.

Consider this code:-

Code:
<WebMethod()> _
Public Function CreditCheck(ByVal System As String, ByVal TestLive As String, ByVal Customer As String) As String

  Return GetCreditCheck(System,TestLive,Customer)

End Function

I am building a string of data in the GetCreditCheck function and then exposing it within the Webmethod.
Only the webmethod is doing anything to the string to make it XML. Assuming I am eturning asingle string value, is that acceptable as a valid webservice format?

If I were returning two seperate values within the string in the GetCreditCheck function, I guess I'd have to format that string as XML before it was returned to the Webmethod to differentiate between the two parameters?.



Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
The data is being returned in a soap packet. "Simple Object Access Protocol", it is a basic xml message - you can view it by browsing your wsdl.

To return two values, simply return a string array with 2 elements. - or you can construct a dataset are return it.. what type of client is connecting to your webservice?

Rob
 
Thanks for the WSDL info, I get that bit now.

I don't know yet exactly how the third party will be consuming the web service but I believe it will be over a secure WAN.

I’m very close to having all the answers now. I have even had the joy of returning a dataset from an AS400 as an XML payload on a web method.

I still have a few little general ‘in between the lines’ concept queries I hope you don’t mind helping me with.

Query 1
I have created a Web Method that is a procedure instead of a function.
It accepts parameters but does not return anything as it of course by definition does not have a function return value. Therefore my question is:- is it standard practice to always use a function and not a procedure when hosting a web service?

Query 2
Interestingly your idea to returning a string array does not work. I've looked at a few posts in a few forums that state it works in C# but not VB in .Net. I tried the example below and it fails on the Return. I am using VB.Net 2005. Do you know later versions have a solution to this problem?

Code:
<WebMethod()> _
Public Function MultiParamsArray(ByVal strDummy1 As String, ByVal strDummy2 As String, ByVal strDummy3 As String) As String()

Dim strDummy(2)
strDummy(0) = strDummy1 + " I am the Dummy1 Parameter"
strDummy(1) = strDummy2 + " I am the Dummy2 Parameter"
strDummy(2) = strDummy3 + " I am the Dummy3 Parameter"
Return strDummy

End Function


Query 3
I need to receive a big chunk of data as a parameter to my web service.

Is it standard practice to receive data as an XML data type parameter and use the XML content

OR

is it standard practice to receive an XML fragment as a string parameter and then load it into an XMLDocument to use the XML content?


Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
Im going to dig into the string array. I could have sworn I had it working when last I played with webservices. - Usually I have been on both sides of the webserivce. - Building and conusming, so I have always used dotnet to recieve the data also.. - typically a string array is what you return to a asp.net autocomplete control.

In many cases I have returned a standard dotnet dataset object. (You might find that this works best for you) The dataset allows you to send back multiple tables each with mulitple records and columns and is exceptionally flexable.

The dataset also does a good job of describing what type of data will be in each cell. This is often usefull in deserialization.

(I will do some tinkering - and get back)

Rob
 
OK. Thanks. It's all very interesting stuff.

I do agree the dataset is an excellent way of returning data and will suit most circumstances.

I'm focusing now on how to send big chunks of data ( eg. a sales order with lots of order positions ) as a parameter to a web service I'm hosting. I assume the way to do this is to send an XML fragment as a string parameter and get my webservice to load the string into an XMLDocument. The XML document can then be shredded with the use of some rather long winded code. Is this the way you'd do it?








Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top