Binding to a Web Service : ObjectDataSource « ADO.net Database « ASP.Net






Binding to a Web Service



File: TimeService.asmx

<%@ WebService Language="C#" Class="TimeService" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://www.java2s.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class TimeService  : System.Web.Services.WebService {

    [WebMethod]
    public DateTime GetServerTime() {
        return DateTime.Now;
    }
}
File: Default.aspx

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <form id="form1" runat="server">
    <div>

    <asp:FormView
        id="frmServerTime"
        DataSourceID="srcServerTime"
        CssClass="serverTime"
        Runat="server">
        <ItemTemplate>
        The remote server date and time is: <%# Container.DataItem %>
        </ItemTemplate>
    </asp:FormView>

    <asp:ObjectDataSource
        id="srcServerTime"
        TypeName="TimeService"
        SelectMethod="GetServerTime"
        Runat="server" />

    </div>
    </form>
</body>
</html>

 








Related examples in the same category

1.Binding to a LINQ to SQL Query
2.Using Parameters with the ObjectDataSource Control
3.Using Different Parameter Types
4.Passing Objects as Parameters
5.Filtering Data
6.Handling ObjectDataSource Control Events
7.Handling Method Errors
8.Handling the Object Creating Event
9.Concurrency and the ObjectDataSource Control, ConflictDetection: CompareAllValues / OverwriteChanges
10.Creating a Custom ObjectDataSource Control
11.Creating Custom Parameter Objects
12.Creating a Page Property Parameter
13.Define your own collection for ObjectDataSource
14.objectdatasource with control parameter
15.GridView with ObjectDataSource
16.ObjectDataSource with selectmethod, deletemethod, updatemethod, insertmethod
17.ObjectDataSource based on XML
18.ObjectDataSource and backend database