如何:将相关信息分组到单个 Web 服务方法中
下面的代码示例演示如何将相关信息分组到单个 Web 服务方法中。 此示例阐释了使用 ASP.NET 创建的 XML Web services 的设计准则主题中阐述的准则之一。
示例
<%@ 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
请参见
概念
使用 ASP.NET 创建的 XML Web services 的设计准则
版权所有 (C) 2007 Microsoft Corporation。保留所有权利。