I am New to this site. I am currently working on wcf . I am trying to achieve somethig from this hard work but i am facing some problems.I have WCF service running in my MS Visual Stuido 2015 which have local class named AccountBalance and this class got several string propertys like account_number, account_balace etc .I created database in MS Sql server. Currently i am consuming wcf service in a console Application .I am trying to retrive the record from database in console window by using account number as key. when i enter the account number it should display the rest of record from database in console application but i getting error saying that and i can not run it . cannot convert from 'string' to MyService.AccountBalanceRequest' Here is class code which inherits from another base class..
[DataContract]
public class AccountBalanceRequest : Current_Account_Details
{
string account_number;
[DataMember]
public string Account_Number
{
get { return account_number; }
set { account_number = value; }
}
}
}
Here is ADO.NET CODE..
public bool AccountBalanceCheek(AccountBalanceRequest accountNumber)
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("SELECT * FROM
Current_Account_Details WHERE Account_Number ='" +
accountNumber.Account_Number + "'", conn))
{
cmd.Parameters.AddWithValue("@Account_Number",
accountNumber.Account_Number);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
return true;
}
}
}
Here is Console Application Code..
public static void Balance()
{
MyService.HalifaxCurrentAccountServiceClient currentAccount = new MyService.HalifaxCurrentAccountServiceClient("NetTcpBinding_IHalifaxCurrentAccou
ntService");
MyService.AccountBalanceRequest cs = new MyService.AccountBalanceRequest();
string AccountNumber;
Console.WriteLine("\nEnter your Account Number--------:");
AccountNumber = Console.ReadLine();
cs.Account_Number = AccountNumber;
MyService.AccountBalanceRequest cs1 =
currentAccount.AccountBalanceCheek(AccountNumber);//Error on this line.
Console.WriteLine("Your Account Number is :" + cs.Account_Number);
Console.WriteLine("Your Account Type :" + cs.Account_Balance);
Console.WriteLine("Your Account Account Fee :" + cs.Account_Fee);
Console.WriteLine("Your Account Balance:" + cs.Account_Balance);
Console.WriteLine("Your Account Over Draft Limit :" + cs.Over_Draft_Limit);
Console.Write("--------------------------");
Console.ReadLine();
}
i also tried this way as well. the code did rise any error but did not give expected result. here is the code.
public static void Balance()
{
MyService.HalifaxCurrentAccountServiceClient currentAccount = new MyService.HalifaxCurrentAccountServiceClient("NetTcpBinding_IHalifaxCurrentAccountService");
MyService.AccountBalanceRequest cs = new MyService.AccountBalanceRequest();
string AccountNumber;
Console.WriteLine("\nEnter your Account Number--------:");
AccountNumber = Console.ReadLine();
cs.Account_Number = AccountNumber;
// MyService.AccountBalanceRequest cs1 = currentAccount.AccountBalanceCheek(AccountNumber);
if (currentAccount.AccountBalanceCheek(cs))
{
Console.WriteLine("Your Account Number is :" + cs.Account_Number);
Console.WriteLine("Your Account Type :" + cs.Account_Balance);
Console.WriteLine("Your Account Account Fee :" + cs.Account_Fee);
Console.WriteLine("Your Account Balance:" + cs.Account_Balance);
Console.WriteLine("Your Account Over Draft Limit :" + cs.Over_Draft_Limit);
Console.Write("--------------------------");
Console.ReadLine();
//Console.Clear();
}
}
Here is the image for out put. This is image of the out put
Right way is:
currentAccount.AccountBalanceCheek(cs);
Not:
currentAccount.AccountBalanceCheek(AccountNumber);
Because the type of parameter is MyService.AccountBalanceRequest
, not string
.
I hope to be helpful for you :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.