Intersoft Support Center

Bind to WCF Service

This walkthrough shows you how to configure client binding using WcfService mode.

During this walkthrough, you will learn how to do the following:

  • Create WcfService
  • Bind WcfService into WebGrid

 Prerequisites

In order to complete this walkthrough, you will need the following:

  • Access to SQL.
  • Visual Studio 2008/2010 Application.

 Step-By-Step Instructions

To configure client binding using WcfService mode

  1. Launch Visual Studio.NET 2008.
  2. Click on File menu, then select New and click Web Site.
  3. Select ASP.NET Web Site in the Template box and set Location to HTTP.
  4. Named the Web Site and click OK.
  5. In the Solution Explorer, right-click on App_Data and select Add Existing Item.
  6. Browse and add NorthWind.mdf in C:\Program Files\Intersoft Solutions\Data (Default installation folder).
  7. Add new page in App_Code and select Linq to Sql classes template. Named it Northwind.dbml.



  8. Drag Table Customer in Northwind.mdf from Server Explorer and set SerializationMode into Unidirectional.



  9. Right-click on Project's name and select Add New Item.
  10. Select Intersoft AppForm in the My Templates box and named it as Walkthrough.aspx.
  11. Drag WebGrid instance from ToolBar to WebForm.
  12. Right-click on WebGrid and choose Properties. You need to expand ClientBindingSettings and set the following properties.
    Property Value
    DataSourceType WcfService
    ServiceUrl ~/WebGrid/ClientBindingServiceEvents/WcfService.asmx
    ServiceMethods - SelectMethod GetCustomers

    Set the other properties based on the properties on aspx code below.
    <ISWebGrid:WebGrid ID="WebGrid1" runat="server" Height="250px" UseDefaultStyle="True"
        Width="500px" BindingOperationMode="ClientBinding">            
        <RootTable>
            <Columns>
                <ISWebGrid:WebGridColumn Caption="CustomerID" DataMember="CustomerID" Name="CustomerID"
                    Width="100px">
                </ISWebGrid:WebGridColumn>
                <ISWebGrid:WebGridColumn Caption="ContactTitle" DataMember="ContactTitle" Name="ContactTitle"
                    Width="100px">
                </ISWebGrid:WebGridColumn>
            </Columns>
        </RootTable>
        <ClientBindingSettings DataSourceType="WcfService" ServiceUrl="~/WebGrid/ClientBindingServiceEvents/WcfService.svc">
            <ServiceMethods SelectMethod="GetCustomers" />
        </ClientBindingSettings>
    </ISWebGrid:WebGrid>            
    

  13. Create at the WcfService.svc in the same level with your aspx name.



  14. Go to App_Code and add method GetCustomers in WcfService.cs.

    C# Copy ImageCopy Code
    [System.Web.Script.Services.ScriptService] )[WebMethod]
    public List<customer> GetCustomers()
    { 
        NorthwindDataContext context = new NorthwindDataContext();
        context.DeferredLoadingEnabled = false;
        context.ObjectTrackingEnabled = false; 
        return context.Customers.ToList();
    }
    

  15. Save all the pages. Browse WcfService.svc to ensure that the service works.
  16. After the WcfService works without error, simply run the project Walkthrough.aspx

Previous Next