?
Solved

Can a C# webservice have a single DataSet parameter to handle a multi-relational XML/SOAP post?

Posted on 2007-11-21
15
Medium Priority
?
380 Views
Last Modified: 2013-11-26
I have a webpage that is accessing a C#/.NET webservice.  It sends some XML that has several children (and the children have children as well).  For example:
<data>
   <first_child_of_data>
       <first_child_of_first_child>
       </first_child_of_first_child>
   </first_child_of_data>
   <second_child_of_data>
       <first_child_of_second_child>
       <first_child_of_second_child>
   </second_child_of_data>
</data>

My webservice has a single function.  My question is on the webservice side, do i have to make my function have a parameter for each tag(or row) or can I collect the entire XML/Soap post in one DataSet parameter, like so:
    [WebMethod]
    public string XMLtoString(DataSet datastream) { }
 
And if so, my main goal is to take that XML post and return a single string like:
string returnstring = <data><first_child_of_data><first_child_of_first_child></first_child_of_first_child></first_child_of_data>   <second_child_of_data><first_child_of_second_child><first_child_of_second_child></second_child_of_data></data>";

Besides the yes or no answer, some sample code for the string building would be much appreciated.

Thanks
0
Comment
Question by:RichardRiga
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 3
15 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 20328333
I would go the DataSet route, since it is serializable, and can bundle all the information that you need into a single entity.

Bob
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20328348
You could have just one dataset instead of calling it for every row.
The dataset has a WriteXML method to convert the dataset to string(XML)
0
 
LVL 1

Author Comment

by:RichardRiga
ID: 20328393
thanks for the quick responses, but can one of you show me *how* to do that?  I have the single DataSet parameter already and I'm using WriteXML but i'm messing something up.   thanks
0
Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

 
LVL 21

Expert Comment

by:surajguptha
ID: 20328401
>>but i'm messing something up
More details would help :)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20328517
If you are trying to create a custom XML document (because DataSet.WriteXml doesn't cut it), then you could create an XmlDocument and use methods like CreateElement.

Example:

Create a New XML File Using XmlDocument
http://www.devx.com/tips/Tip/21168

Bob
0
 
LVL 1

Author Comment

by:RichardRiga
ID: 20328571
Below is my webmethod.  When I run the client I receive a series of numbers that have nothing to do with the data submitted.  It seems random but its the same numbers each time its run.  What I expect to see is all the tags and their values in a single string as posted originally.  Some extra info... if i use         return datastream.Tables.Count.ToString() I get a 0 as a return value.  I had thought that each of the children became tables of their own, but I guess not.

    [WebMethod]
    public string XMLtoString(DataSet datastream)
    {      
        string returnstring = "";
        byte[] arr;
       
        MemoryStream stream = new MemoryStream();      
        datastream.WriteXml(stream);
        arr = stream.ToArray();
       
        for (int ix = 0; ix < arr.Length; ix++)
        {
            returnstring += arr.GetValue(ix).ToString();
        }
         
        return returnstring;
  }
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20328608
Are you saying that the incoming DataSet doesn't have any tables attached?

Bob
0
 
LVL 1

Author Comment

by:RichardRiga
ID: 20328712
Bob, right.

Say I submit the above sample XML via a SOAP post.  When it gets to the webmethod and i use the         return datastream.Tables.Count.ToString() i get a zero as a response.
0
 
LVL 1

Author Comment

by:RichardRiga
ID: 20328736
Learned one, hi.

I'm not trying to create a custom XML document.

I guess, in a nutshell, i'm trying to have my webmethod be able accept ANY xml/soap post then send back a string representation of it, tags and values.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20328805
Hmmm, I am trying to understand the value of this web method.  Are you trying to create a different representation for the incoming XML text?

Bob
0
 
LVL 1

Author Comment

by:RichardRiga
ID: 20328882
I am trying to send an XML/SOAP message to a webservice.  regardless of the number of children, grandchildren, etc, I'd like to have the webservice method accept it as a single DataSet parameter, then spit it back out as a string.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20328935
How are you constructing the DataSet to pass into the web method?  Since DataSet.Tables.Count = 0, it sounds like it is not working very well.

Bob
0
 
LVL 1

Author Comment

by:RichardRiga
ID: 20328989
What do you mean constructing?  I assumed that the XML post would come in as the DataSet.
0
 
LVL 1

Author Comment

by:RichardRiga
ID: 20329039
like:
=============================
==<data>                                       ==
==   <first_child_of_data>             ==
==      <first_child_of_first_child>  ==    
==       </first_child_of_first_child>==                                                    
==   </first_child_of_data>             ==                                                          
==</data>                                       ==                                                                      
==============================
                     ||
                     ||
             to webservice
                    ||
                    ||
============================================
== [WebMethod]                                                         ==
==public string XMLtoString(DataSet datastream) { } ==
============================================
                  ||
                  ||
         returns string
==
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20329134
You mean to say that you directly write the XML into the webservice rather than using a proxy?
You need not send it to the web service just to get a string. you could just use a function to convert it to string

0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question