Click here to Skip to main content
15,895,084 members
Articles / Web Development / ASP.NET

How to Build Flexible and Reusable WCF Services

Rate me:
Please Sign up or sign in to vote.
4.85/5 (13 votes)
6 May 2013GPL313 min read 77.2K   1.9K   126  
Design Patterns and best practices for building flexible and reusable WCF services.
<Window xmlns:xom="clr-namespace:Xomega.Framework;assembly=Xomega.Framework"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:l="clr-namespace:AdventureWorks.Client.Objects;assembly=AdventureWorks.Client.Objects"
        x:Class="AdventureWorks.Client.WPF.EmployeeSearch"
        Title="Employee Search"
        Height="640"
        Width="960">
   <Grid Margin="10">
      <Grid.RowDefinitions>
         <RowDefinition Height="Auto"/>
         <RowDefinition Height="Auto"/>
         <RowDefinition Height="*"/>
         <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>
      <Grid Name="pnlCriteria">
         <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
         </Grid.ColumnDefinitions>
         <Label Grid.Row="0" Grid.Column="0" Name="lblFirstName">_First Name:</Label>
         <ComboBox Grid.Row="0" Grid.Column="1"
                   xom:Property.Label="{Binding ElementName=lblFirstName}"
                   Name="ctlFirstNameOperator"
                   xom:Property.Name="{x:Static l:EmployeeCriteria.FirstNameOperator}"
                   Style="{StaticResource OperatorStyle}"/>
         <TextBox Grid.Row="0" Grid.Column="2" Grid.ColumnSpan="2" Name="ctlFirstName"
                  xom:Property.Name="{x:Static l:EmployeeCriteria.FirstName}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Grid.Row="1" Grid.Column="0" Name="lblLastName">_Last Name:</Label>
         <TextBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3"
                  xom:Property.Label="{Binding ElementName=lblLastName}"
                  Name="ctlLastName"
                  xom:Property.Name="{x:Static l:EmployeeCriteria.LastName}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Grid.Row="2" Grid.Column="0" Name="lblManagerLastName">_Manager Last Name:</Label>
         <TextBox Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3"
                  xom:Property.Label="{Binding ElementName=lblManagerLastName}"
                  Name="ctlManagerLastName"
                  xom:Property.Name="{x:Static l:EmployeeCriteria.ManagerLastName}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Grid.Row="0" Grid.Column="4" Name="lblHireDate">_Hire Date:</Label>
         <ComboBox Grid.Row="0" Grid.Column="5"
                   xom:Property.Label="{Binding ElementName=lblHireDate}"
                   Name="ctlHireDateOperator"
                   xom:Property.Name="{x:Static l:EmployeeCriteria.HireDateOperator}"
                   Style="{StaticResource OperatorStyle}"/>
         <TextBox Grid.Row="0" Grid.Column="6" Name="ctlHireDate"
                  xom:Property.Name="{x:Static l:EmployeeCriteria.HireDate}"
                  Style="{StaticResource ControlStyle}"/>
         <TextBox Grid.Row="0" Grid.Column="7" Name="ctlHireDate2"
                  xom:Property.Name="{x:Static l:EmployeeCriteria.HireDate2}"
                  Style="{StaticResource ControlStyle}"/>
         <Label Grid.Row="1" Grid.Column="4" Name="lblState">_State:</Label>
         <ComboBox Grid.Row="1" Grid.Column="5"
                   xom:Property.Label="{Binding ElementName=lblState}"
                   Name="ctlStateOperator"
                   xom:Property.Name="{x:Static l:EmployeeCriteria.StateOperator}"
                   Style="{StaticResource OperatorStyle}"/>
         <ListBox Grid.Row="1" Grid.Column="6" Grid.ColumnSpan="2" Name="ctlState"
                  xom:Property.Name="{x:Static l:EmployeeCriteria.State}"
                  Style="{StaticResource ControlStyle}"
                  MaxHeight="58"/>
         <Label Grid.Row="2" Grid.Column="4" Name="lblZipcode">_Zipcode:</Label>
         <ComboBox Grid.Row="2" Grid.Column="5"
                   xom:Property.Label="{Binding ElementName=lblZipcode}"
                   Name="ctlZipcodeOperator"
                   xom:Property.Name="{x:Static l:EmployeeCriteria.ZipcodeOperator}"
                   Style="{StaticResource OperatorStyle}"/>
         <TextBox Grid.Row="2" Grid.Column="6" Grid.ColumnSpan="2" Name="ctlZipcode"
                  xom:Property.Name="{x:Static l:EmployeeCriteria.Zipcode}"
                  Style="{StaticResource ControlStyle}"/>
      </Grid>
      <Button Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Top"
              Margin="0,10,100,10"
              Name="btnSearch"
              Width="75"
              Click="btnSearch_Click">_Search</Button>
      <Button Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Top"
              Margin="0,10,0,10"
              Name="btnReset"
              Width="75"
              Click="btnReset_Click">_Reset</Button>
      <Button Grid.Row="3" HorizontalAlignment="Left" VerticalAlignment="Top"
              Margin="0,10,0,10"
              Name="btnNew"
              Width="75">_New...</Button>
      <Button Grid.Row="3" HorizontalAlignment="Right" VerticalAlignment="Top"
              Margin="0,10,100,10"
              Name="btnDetails"
              Width="75">_Details...</Button>
      <Button Grid.Row="3" HorizontalAlignment="Right" VerticalAlignment="Top"
              Margin="0,10,0,10"
              Name="btnClose"
              Width="75"
              Click="btnClose_Click">_Close</Button>
      <ListView Grid.Row="2" Name="gridResults">
         <ListView.View>
            <GridView>
               <GridView.Columns>
                  <GridViewColumn Header="Id">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:EmployeeRowObject.Id}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="First Name">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:EmployeeRowObject.FirstName}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="Last Name">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:EmployeeRowObject.LastName}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="Title">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:EmployeeRowObject.Title}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="Hire Date">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:EmployeeRowObject.HireDate}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="Manager">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:EmployeeRowObject.Manager}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="Salaried">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <CheckBox xom:Property.Name="{x:Static l:EmployeeRowObject.Salaried}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="Current">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <CheckBox xom:Property.Name="{x:Static l:EmployeeRowObject.Current}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="Gender">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:EmployeeRowObject.Gender}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="State Id">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:EmployeeRowObject.StateId}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="Street Address">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:AddressObject.StreetAddress}"
                                      xom:Property.ChildObject="{x:Static l:EmployeeRowObject.Address}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="City">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:AddressObject.City}"
                                      xom:Property.ChildObject="{x:Static l:EmployeeRowObject.Address}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="State">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:AddressObject.State}"
                                      xom:Property.ChildObject="{x:Static l:EmployeeRowObject.Address}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="Zipcode">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:AddressObject.Zipcode}"
                                      xom:Property.ChildObject="{x:Static l:EmployeeRowObject.Address}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="Country">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock xom:Property.Name="{x:Static l:AddressObject.Country}"
                                      xom:Property.ChildObject="{x:Static l:EmployeeRowObject.Address}"/>
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
               </GridView.Columns>
            </GridView>
         </ListView.View>
      </ListView>
   </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Architect Xomega.Net
United States United States
Xomega Team is striving to increase productivity and development quality by utilizing Model Driven Development coupled with Code Generation and the best design practices for application development.
We provide MDD tools, code generators and frameworks for Visual Studio and .Net development.
Visit us at http://www.xomega.net
This is a Organisation

1 members

Comments and Discussions