Step 1: Download and run the last application and save URL
Step 2: Create a new web application
Step 3: Open visual studio command prompt and type
svcutil.exe http://localhost:4864/MyFIrst_WCFApplication/Service.svc?wsdl
And press Enter.
This will give you two files, add this cs file to your Client application and add config file information to web.config file as given below.
  1. <system.serviceModel>
  2. <bindings>
  3. <wsHttpBinding>
  4. <binding name="WSHttpBinding_IService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
  5. <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
  6. <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
  7. <security mode="Message">
  8. <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
  9. <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/>
  10. </security>
  11. </binding>
  12. </wsHttpBinding>
  13. </bindings>
  14. <client>
  15. <endpoint address="http://localhost:4864/MyFIrst_WCFApplication/Service.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService" contract="IService" name="WSHttpBinding_IService">
  16. <identity>
  17. <dns value="localhost"/>
  18. </identity>
  19. </endpoint>
  20. </client>
  21. </system.serviceModel>
Step 4: Add a Login.Aspx page as given below..
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head id="Head1" runat="server">
  5. <title></title>
  6. <style type="text/css">
  7. .style1
  8. {
  9. width: 100%;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <form id="form1" runat="server">
  15. <div>
  16. <div style="height: 150px">
  17. </div>
  18. <div>
  19. <table class="style1">
  20. <tr>
  21. <td> </td>
  22. <td> </td>
  23. <td> </td>
  24. <td> </td>
  25. </tr>
  26. <tr>
  27. <td> </td>
  28. <td>User name</td>
  29. <td>
  30. <asp:TextBox ID="txt_Username" runat="server" Width="200px"></asp:TextBox>
  31. </td>
  32. <td> </td>
  33. </tr>
  34. <tr>
  35. <td> </td>
  36. <td>Password</td>
  37. <td>
  38. <asp:TextBox ID="txt_Password" runat="server" TextMode="Password" Width="200px"></asp:TextBox>
  39. </td>
  40. <td> </td>
  41. </tr>
  42. <tr>
  43. <td> </td>
  44. <td> </td>
  45. <td>
  46. <asp:Button ID="btn_Login" runat="server" OnClick="btn_Login_Click" Text="login" />
  47. </td>
  48. <td> </td>
  49. </tr>
  50. <tr>
  51. <td> </td>
  52. <td> </td>
  53. <td>
  54. <asp:Label ID="lbl_error" runat="server"></asp:Label>
  55. </td>
  56. <td> </td>
  57. </tr>
  58. </table>
  59. </div>
  60. </div>
  61. </form>
  62. </body>
  63. </html>
Step 5: Go to Login.aspx.cs page and write the below code.
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.ServiceModel;
  8. public partial class Login : System.Web.UI.Page
  9. {
  10. ServiceClient wcfservice = new ServiceClient();
  11. protected void Page_Load(object sender, EventArgs e)
  12. {
  13. }
  14. protected void btn_Login_Click(object sender, EventArgs e)
  15. {
  16. bool result = wcfservice.Check_Login(txt_Username.Text, txt_Password.Text);
  17. lbl_error.Text = result.ToString();
  18. }
  19. }
Step 6: In same way, create for register page.
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <head id="Head1" runat="server">
  4. <title></title>
  5. <style type="text/css">
  6. .style1
  7. {
  8. width: 100%;
  9. }
  10. </style>
  11. </head>
  12. <body>
  13. <form id="form1" runat="server">
  14. <div>
  15. <div style="height: 150px">
  16. </div>
  17. <div>
  18. <table class="style1">
  19. <tr>
  20. <td> </td>
  21. <td> </td>
  22. <td> </td>
  23. <td> </td>
  24. </tr>
  25. <tr>
  26. <td> </td>
  27. <td>User name</td>
  28. <td>
  29. <asp:TextBox ID="txt_Username" runat="server" Width="200px"></asp:TextBox>
  30. <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txt_Username"
  31. ErrorMessage="Can't Be Blank" Font-Bold="True" ForeColor="#000066"></asp:RequiredFieldValidator>
  32. </td>
  33. <td> </td>
  34. </tr>
  35. <tr>
  36. <td> </td>
  37. <td>Password</td>
  38. <td>
  39. <asp:TextBox ID="txt_Password" runat="server" TextMode="Password" Width="200px"></asp:TextBox>
  40. <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txt_Password"
  41. ErrorMessage="Can't Be Blank" Font-Bold="True" ForeColor="#000066"></asp:RequiredFieldValidator>
  42. </td>
  43. <td> </td>
  44. </tr>
  45. <tr>
  46. <td> </td>
  47. <td>Confirm Password</td>
  48. <td>
  49. <asp:TextBox ID="txt_CNF_Password" runat="server" TextMode="Password" Width="200px"></asp:TextBox>
  50. <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txt_CNF_Password"
  51. ErrorMessage="Can't Be Blank" Font-Bold="True" ForeColor="#000066"></asp:RequiredFieldValidator>
  52. <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="txt_Password"
  53. ControlToValidate="txt_CNF_Password" ErrorMessage=" Password Not matched" Font-Bold="True"
  54. ForeColor="#000066"></asp:CompareValidator>
  55. </td>
  56. <td> </td>
  57. </tr>
  58. <tr>
  59. <td> </td>
  60. <td>First Name</td>
  61. <td>
  62. <asp:TextBox ID="txt_FName" runat="server" Width="200px"></asp:TextBox>
  63. <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txt_FName"
  64. ErrorMessage="Can't Be Blank" Font-Bold="True" ForeColor="#000066"></asp:RequiredFieldValidator>
  65. </td>
  66. <td> </td>
  67. </tr>
  68. <tr>
  69. <td> </td>
  70. <td>Last Name</td>
  71. <td>
  72. <asp:TextBox ID="txt_LName" runat="server" Width="200px"></asp:TextBox>
  73. <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txt_LName"
  74. ErrorMessage="Can't Be Blank" Font-Bold="True" ForeColor="#000066"></asp:RequiredFieldValidator>
  75. </td>
  76. <td> </td>
  77. </tr>
  78. <tr>
  79. <td> </td>
  80. <td>Address</td>
  81. <td>
  82. <asp:TextBox ID="txt_Address" runat="server" Width="200px"></asp:TextBox>
  83. <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txt_Address"
  84. ErrorMessage="Can't Be Blank" Font-Bold="True" ForeColor="#000066"></asp:RequiredFieldValidator>
  85. </td>
  86. <td> </td>
  87. </tr>
  88. <tr>
  89. <td> </td>
  90. <td>City</td>
  91. <td>
  92. <asp:TextBox ID="txt_City" runat="server" Width="200px"></asp:TextBox>
  93. <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="txt_City"
  94. ErrorMessage="Can't Be Blank" Font-Bold="True" ForeColor="#000066"></asp:RequiredFieldValidator>
  95. </td>
  96. <td> </td>
  97. </tr>
  98. <tr>
  99. <td> </td>
  100. <td>Mobile No</td>
  101. <td>
  102. <asp:TextBox ID="txt_Mobile" runat="server" Width="200px"></asp:TextBox>
  103. <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="txt_Mobile"
  104. ErrorMessage="Can't Be Blank" Font-Bold="True" ForeColor="#000066"></asp:RequiredFieldValidator>
  105. </td>
  106. <td> </td>
  107. </tr>
  108. <tr>
  109. <td> </td>
  110. <td> </td>
  111. <td>
  112. <asp:Button ID="btn_Register" runat="server" OnClick="btn_Register_Click" Text="Register" />
  113. </td>
  114. <td> </td>
  115. </tr>
  116. <tr>
  117. <td> </td>
  118. <td> </td>
  119. <td>
  120. <asp:Label ID="lbl_error" runat="server"></asp:Label>
  121. </td>
  122. <td> </td>
  123. </tr>
  124. <tr>
  125. <td> </td>
  126. <td> </td>
  127. <td> </td>
  128. <td> </td>
  129. </tr>
  130. </table>
  131. </div>
  132. </div>
  133. </form>
  134. </body>
And
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.ServiceModel;
  8. using System.ServiceModel.Description;
  9. public partial class Register : System.Web.UI.Page
  10. {
  11. // ServiceClient wcf = new ServiceClient();
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14. }
  15. protected void btn_Register_Click(object sender, EventArgs e)
  16. {
  17. ServiceClient wcf = new ServiceClient();
  18. try
  19. {
  20. string result = wcf.Register_Login(txt_Username.Text, txt_Password.Text, txt_FName.Text, txt_LName.Text, txt_Address.Text, txt_Mobile.Text, txt_City.Text);
  21. lbl_error.Text = result.ToString();
  22. }
  23. catch (FaultException<string> ex)
  24. {
  25. lbl_error.Text = ex.Message.ToString();
  26. }
  27. }
  28. public class CustomException
  29. {
  30. public string Title;
  31. public string ExceptionMessage;
  32. public string InnerException;
  33. public string StackTrace;
  34. }
  35. }
Run the application, if you get any error from server-side, it will show an error that is given on webservice program. For more find the code.