DevProve
DevProve

Reputation: 192

How WCF work as datasource?

As title how a paging wcf can work as datasource? Dataservicequery had setentitysetpagesize the records of select had limited. How should it work like as datasource in this case. If bind it to web control the total record will be wrong when query all the record and the paging also have paging. I had gonna crazy after due with this.

Upvotes: 2

Views: 1697

Answers (1)

Bilal lilla
Bilal lilla

Reputation: 658

You need to use generic classes as a return type and made that classes serializable and then use Object datasource in front end . I am sure about that it works.

Like: Bizz layer as W.C.F service

 public List<Employee> GetEmployees()
        {

            try
            {

                List<Employee> emp = new List<Employee>();
                emp.Add(new Employee { Code = 1, DepartMentCode = 2, FatherName = "FatherName", ManagerCode = 2,  Name = "Bilal",ManagerName="mnagername", PhoneNumber = "24421" });
            return emp;
        }

        catch (TimeoutException te)
        {
            throw te;
        }
        catch (FaultException fe)
        {
            throw new FaultException();
        }
        catch (CommunicationException ce)
        {
            throw new CommunicationException();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            if (client != null)
            {
                client.Close();
            }
        }
    }

//entity class

 [Serializable()]
  [DataContract()]
  public class Employee
  {
    [DataMember]
    public int Code { get; set; }
    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public string FatherName { get; set; }
    [DataMember]
    public string PhoneNumber { get; set; }
    [DataMember]
    public int DepartMentCode { get; set; }
    [DataMember]
    public int ManagerCode { get; set; }
    [DataMember]
    public string ManagerName { get; set; }
}

//this is page level code . i hope you willunderstand that.

  <div class="EmployeeMain">
    <div class="link" onclick="Show_Popup();">
        New Employee</div>
    <fieldset>
        <legend>Employees Details </legend>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ODSEmployee"
            OnRowEditing="GridView1_RowEditing" BackColor="LightGoldenrodYellow" BorderColor="Tan"
            BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" Width="100%"
            AllowPaging="True">
            <AlternatingRowStyle BackColor="PaleGoldenrod" />
            <Columns>
                <asp:BoundField FooterText="EmployeeID" DataField="Code" HeaderText="EmployeeID" />
                <asp:BoundField FooterText="Name" DataField="Name" HeaderText="Name" />
                <asp:BoundField FooterText="Father Name" DataField="FatherName" HeaderText="Father Name" />
                <asp:BoundField FooterText="Phone Number" DataField="PhoneNumber" HeaderText="Phone Number" />
                <asp:TemplateField FooterText="manager" HeaderText="Manager">
                    <ItemTemplate>
                        <asp:Label ID="lblMangerName" Text='<%# Eval("ManagerName") %>' runat="server"></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlManager" runat="server" DataSourceID="ManagersDataSource"
                            DataTextField="ManagerName" DataValueField="ManagerCode" SelectedValue='<%# Bind("ManagerCode") %>'
                            AppendDataBoundItems="True">
                        </asp:DropDownList>
                        <asp:ObjectDataSource runat="server" ID="ManagersDataSource" SelectMethod="GetManagers"
                            TypeName="mytest.WebApplication.BizzLayerService.EmployeeClient"></asp:ObjectDataSource>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
            </Columns>
            <FooterStyle BackColor="Tan" />
            <HeaderStyle BackColor="Tan" Font-Bold="True" />
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
            <SortedAscendingCellStyle BackColor="#FAFAE7" />
            <SortedAscendingHeaderStyle BackColor="#DAC09E" />
            <SortedDescendingCellStyle BackColor="#E1DB9C" />
            <SortedDescendingHeaderStyle BackColor="#C2A47B" />
        </asp:GridView>
        <asp:ObjectDataSource ID="ODSEmployee" runat="server" DeleteMethod="DeleteEmployeeRecord"
            InsertMethod="SaveEmployeeRecord" SelectMethod="GetEmployees" TypeName="mytest.WebApplication.BizzLayerService.EmployeeClient"
            UpdateMethod="UpdateEmployeeRecord">
            <DeleteParameters>
                <asp:Parameter Name="empCode" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="empCode" Type="Int32" />
                <asp:Parameter Name="empName" Type="String" />
                <asp:Parameter Name="empFatherName" Type="String" />
                <asp:Parameter Name="empPhoneNumber" Type="String" />
                <asp:Parameter Name="empAddress" Type="String" />
                <asp:Parameter Name="empDeparmentCode" Type="Int32" />
                <asp:Parameter Name="EmpManagerCode" Type="Int32" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="empCode" Type="Int32" />
                <asp:Parameter Name="empName" Type="String" />
                <asp:Parameter Name="empFatherName" Type="String" />
                <asp:Parameter Name="empPhoneNumber" Type="String" />
                <asp:Parameter Name="empAddress" Type="String" />
                <asp:Parameter Name="empDeparmentCode" Type="Int32" />
                <asp:Parameter Name="EmpManagerCode" Type="Int32" />
            </UpdateParameters>
        </asp:ObjectDataSource>
        <br />
    </fieldset>
</div>
<div class="newAcount">
    <table>
    <tr>
    <td colspan="2">
    <h1>New Employee Record</h1>
    </td>
    </tr>
        <tr>
            <td>
                Name
            </td>
            <td>
                <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Father Name
            </td>
            <td>
                <asp:TextBox ID="txtFathername" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Phone Number
            </td>
            <td>
                <asp:TextBox ID="txtPhonuNumber" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Address
            </td>
            <td>
                <asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                Department code
            </td>
            <td>
                <asp:DropDownList ID="ddlDeptCode" runat="server">
                </asp:DropDownList>

            </td>
        </tr>
        <tr>
            <td>
                Manager Code
            </td>
            <td>
              <asp:DropDownList ID="ddlManagerName" runat="server">
                </asp:DropDownList>

            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="btnSaveRecord" runat="server" Text="Button" />
            </td>
            <td>
                <input id="Button1" type="button" value="close" onclick="Close_Popup()" />
            </td>
        </tr>
    </table>
</div>

Upvotes: 2

Related Questions