Share via


How to: Group Related Information into a Single Web Service Method

This topic is specific to a legacy technology. XML Web services and XML Web service clients should now be created using Windows Communication Foundation.

The following code example demonstrates how to group related information into a single Web service method. This example illustrates one of the guidelines explained in the topic, Design Guidelines for XML Web Services Created Using ASP.NET.

Example

<%@ WebService Language="C#" Class="DataService" %>
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
public class DataService {
   [WebMethod]
   public DataSet GetTitleAuthors() {
        SqlConnection myConnection = new SqlConnection("Persist Security Info=False;Integrated Security=SSPI;server=localhost;database=pubs");
        SqlDataAdapter myCommand1 = new SqlDataAdapter ("select * from Authors", myConnection);
        SqlDataAdapter myCommand2 = new SqlDataAdapter("select * from Titles", myConnection);
        DataSet ds = new DataSet();
        myCommand1.Fill(ds, "Authors");
        myCommand2.Fill(ds, "Titles");
        return ds;
   }
}
<%@ WebService Language="VB" Class="DataService" %>
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services
Public Class DataService   
    <WebMethod> _
    Public Function GetTitleAuthors() As DataSet
        Dim myConnection As New SqlConnection("Persist Security Info=False;Integrated Security=SSPI;server=localhost;database=pubs")
        Dim myCommand1 As New SqlDataAdapter("select * from Authors", myConnection)
        Dim myCommand2 As New SqlDataAdapter("select * from Titles", myConnection)
        Dim ds As New DataSet()
        myCommand1.Fill(ds, "Authors")
        myCommand2.Fill(ds, "Titles")
        Return ds
    End Function
End Class

See Also

Concepts

Design Guidelines for XML Web Services Created Using ASP.NET