title: Wcf Rest Service Return Number Conversion Error
body: <p>I am consuming Wcf Rest Service into Angular JS Application . I am trying to display single record based on account number in input filed. But when i click the submit button to display the record then i got following errors in Google Chrome Network Tap.</p>
  
  <p><strong>The server encountered an error processing the request. The exception message is 'Conversion failed when converting the nvarchar value '{Account_Number}15' to data type int.'. See server logs for more details. The exception stack trace is:</strong></p>
  
  <p>And its returns 400 Bad Request on Post Method Operation .</p>
  
  <p>Here is the interface .</p>
  
  <pre><code> [OperationContract]
         [WebInvoke(Method = "POST",
         RequestFormat = WebMessageFormat.Json,
         ResponseFormat = WebMessageFormat.Json,
         UriTemplate = "/GetAccountDetails/{Account_Number}")]
          string  GetAccountDetails(string Account_Number);
  </code></pre>
  
  <p>Here is the Implementation.</p>
  
  <pre><code> public string GetAccountDetails(string Account_Number)
          {
              List&lt;object&gt; customers = new List&lt;object&gt;();
              string sql = "SELECT * FROM Current_Account_Holder_Details WHERE Account_Number = @Account_Number";
              using (SqlConnection conn = new SqlConnection())
              {
                  conn.ConnectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
                  using (SqlCommand cmd = new SqlCommand(sql))
                  {
                      cmd.Parameters.AddWithValue("@Account_Number", Account_Number);
                      cmd.Connection = conn;
                      conn.Open();
                      using (SqlDataReader sdr = cmd.ExecuteReader())
                      {
                          while (sdr.Read())
                          {
  
                              customers.Add(new
                              {
                                  Tittle = sdr["Tittle"],
                                  Account_Holder_First_Name = sdr["Account_Holder_First_Name"],
                                  Account_Holder_Last_Name = sdr["Account_Holder_Last_Name"],
                                  Account_Holder_DOB = sdr["Account_Holder_DOB"],
                                  Account_Holder_House_No = sdr["Account_Holder_House_No"],
                                  Account_Holder_Street_Name = sdr["Account_Holder_Street_Name"],
                                  Account_Holder_Post_Code = sdr["Account_Holder_Post_Code"],
  
                                  Account_Holder_Occupation = sdr["Account_Holder_Occupation"],
                                  Account_Number = sdr["Account_Number"]
  
  
  
                              });
                          }
                      }
                      conn.Close();
                  }
  
                  return (new JavaScriptSerializer().Serialize(customers));
              }
  
          }
  </code></pre>
  
  <p>Here is the Script code.</p>
  
  <pre><code>var app = angular.module("WebClientModule", [])
      .controller('Web_Client_Controller', ["$scope", 'myService', function ($scope, myService) {
          var Account_Number = $scope.Account_Number;
          $scope.search = function (Account_Number) {
              var promisePostSingle = myService.postbyId(Account_Number);
  
          promisePostSingle.then(function (pl) {
              var res = pl.data;
              $scope.Account_Number = res.Account_Number;
              $scope.Account_Creation_Date = res.Account_Creation_Date;
              $scope.Account_Type = res.Account_Type;
              $scope.Branch_Sort_Code = res.Branch_Sort_Code;
              $scope.Account_Fees = res.Account_Fees;
              $scope.Account_Balance = res.Account_Balance;
              $scope.Over_Draft_Limit = res.Over_Draft_Limit;
  
              //   $scope.IsNewRecord = 0;
          },
              function (errorPl) {
                  console.log('failure loading Employee', errorPl);
              });
      }
      }]);
  
  
  
  
  app.service("myService", function ($http) {
  
      this.postbyId = function (Id) {
          return $http.post("http://localhost:52098/HalifaxIISService.svc/GetAccountDetails/{Account_Number}" + Id);
      };
     })
  </code></pre>
  
  <p>Here is the HTML .</p>
  
  <pre><code>@{
      Layout = null;
  }
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html ng-app="WebClientModule"&gt;
  &lt;head&gt;
      &lt;meta name="viewport" content="width=device-width" /&gt;
  
      &lt;title&gt;AccountBalance&lt;/title&gt;
      &lt;script src="~/Scripts/angular.min.js"&gt;&lt;/script&gt;
  
      &lt;script src="~/RegistrationScript/AccountBalance.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div data-ng-controller="Web_Client_Controller"&gt;
          Enter Account_Number: &lt;input type="text" ng-model="Account_Number" /&gt;
          &lt;input type="button"  value="search" ng-click="search(Account_Number)" /&gt;
  
              &lt;table id="tblContainer"&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;table style="border: solid 2px Green; padding: 5px;"&gt;
                              &lt;tr style="height: 30px; background-color: skyblue; color: maroon;"&gt;
                                  &lt;th&gt;&lt;/th&gt;
                                  &lt;th&gt;Account Number&lt;/th&gt;
                                  &lt;th&gt;Account Creation Date&lt;/th&gt;
                                  &lt;th&gt;Account Type&lt;/th&gt;
                                  &lt;th&gt;Branch Sort Code&lt;/th&gt;
                                  &lt;th&gt;Account Fees&lt;/th&gt;
                                  &lt;th&gt;Account Balance&lt;/th&gt;
                                  &lt;th&gt;Over Draft Limit&lt;/th&gt;
  
                                  &lt;th&gt;&lt;/th&gt;
                                  &lt;th&gt;&lt;/th&gt;
                              &lt;/tr&gt;
                              &lt;tbody data-ng-repeat="user in Users"&gt;
                                  &lt;tr&gt;
                                      &lt;td&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;span&gt;{{user.Account_Number}}&lt;/span&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;span&gt;{{user.Account_Creation_Date}}&lt;/span&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;span&gt;{{user.Account_Type}}&lt;/span&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;span&gt;{{user.Branch_Sort_Code}}&lt;/span&gt;&lt;/td&gt;
  
                                      &lt;td&gt;&lt;span&gt;{{user.Account_Fees}}&lt;/span&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;span&gt;{{user.Account_Balance}}&lt;/span&gt;&lt;/td&gt;
                                      &lt;td&gt;&lt;span&gt;{{user.Over_Draft_Limit}}&lt;/span&gt;&lt;/td&gt;
                                      &lt;td&gt;
  
                                  &lt;/tr&gt;
                              &lt;/tbody&gt;
                          &lt;/table&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
  
                          &lt;div style="color: red;"&gt;{{Message}}&lt;/div&gt;
  
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/div&gt;
          &lt;/body&gt;
  
  
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the Screen Shot on Debugging mode on Wcf Service .
  <a href="https://i.stack.imgur.com/yborm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yborm.png" alt="enter image description here"></a></p>
  
  <p>Here is the result on Google Chrome Console Windows .
  <a href="https://i.stack.imgur.com/wykQs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wykQs.png" alt="enter image description here"></a></p>