Solved

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

Posted on 2007-11-21
15
373 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 500 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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