Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting data from array of DataSet objects returned from web service
    text
    copied!<p>I have a web service that I want to access when it is added as a web reference to my C# project. A particular method in the web service takes a SQL query string and returns the results of the query as a custom type. When I add the web service reference, the method shows up as returning <code>DataSet[]</code> instead of the custom type. This is fine provided I can still somehow access the data returned from the query within those <code>DataSet</code> objects. I ran a particular query that should return 6 rows; I got back a <code>DataSet[]</code> array with 6 elements. However, when I iterate over those <code>DataSet</code> objects, none of them has any tables (via the <code>Tables</code> property on the <code>DataSet</code>). What gives? Where is my data?</p> <p>The web service is tested and works when I use it as a data source in a Report Builder 2.0 report. I am able to send an XML SOAP query to the web service and get back XML results containing my data.</p> <p>Here's a sample of how I'm getting the <code>DataSet[]</code> array:</p> <pre><code>var service = new MyWebService { Credentials = System.Net.CredentialCache.DefaultCredentials }; DataSet[] dataSets = service.MethodThatReturnsQueryResults(queryString); // The body of this loop is skipped: foreach (DataSet ds in dataSets.Where(ds =&gt; ds.Tables.Count &gt; 0)) { // extract data from DataSet ds } </code></pre> <p><strong>Edit:</strong> here is what the method looks like in the auto-generated Reference.cs that got created when I added the web reference:</p> <pre><code>[return: System.Xml.Serialization.XmlArrayItemAttribute("SomeCustomType")] public System.Data.DataSet[] MethodThatReturnsQueryResults( string selectSQLQuery) { object[] results = this.Invoke("MethodThatReturnsQueryResults", new object[] { selectSQLQuery}); return ((System.Data.DataSet[])(results[0])); } </code></pre> <p>So it's definitely returning a <code>System.Data.DataSet[]</code>, but I wonder if something is happening such that the custom type used in the web service, <code>SomeCustomType</code>, is not getting translated correctly in that auto-generated method, hence the empty <code>DataSet</code> objects. I'm hesitant to edit this auto-generated method. I have access to the web service code; should I do something to it to ensure <code>SomeCustomType</code> can be cast to <code>DataSet[]</code>?</p> <p><strong>Edit:</strong> I feel like I could do better if I just got back the raw XML SOAP response from the web service. How can I do this instead of getting the "translated" version that comes back as <code>DataSet[]</code>?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload