我的应用程序中的WCF服务引用 [英] WCF service referencing in my app
问题描述
HI,
我正在忙于构建一个需要能够使用WCF连接到工作数据库的Windows窗体应用程序。
我得到了如何引用它,但现在我被告知创建一个DAL项目和Classes项目来包含我的所有方法,这就是我真的很困惑,因为我的Classes.cs有SQL命令在它,现在我必须在WCF中调用该方法然后在应用程序中获取该方法,这里是我在classes.cs中使用的代码,但是我将如何在WCF中引用它然后再引用到App通过代码自我?
I am busy building a windows forms application that needs to be able to use a WCF to connect to the work Database.
I get how to reference it but now I was told to create a DAL project and Classes project to contain all my methods and that's where I get really confused because my Classes.cs has SQL commands in it and now I have to call the method in the WCF and then get that method in the app it self here is the code that I use in the classes.cs but how would I then reference this in the WCF and then to the App it self via code?
private DataTable getLoginDetails(string username)
{
SqlCommand sqlcmd = new SqlCommand("sp_GetLoginDetails", sqlConn);
sqlcmd.CommandType = CommandType.StoredProcedure;
sqlcmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = username;
DataTable dtUser = new DataTable();
sqlConn.Open();
SqlDataReader sqlDR = sqlcmd.ExecuteReader();
dtUser.Load(sqlDR);
sqlConn.Close();
BGAssetService.Service1Client serviceAsset = new BGAssetService.Service1Client();
serviceAsset.GetLoginDetails(username);
return dtUser;
}
推荐答案
1。创建OperationContracts和DataContracts
2.更新您的服务参考。
3.在您的应用程序中创建WCF客户端
4.您将获得方法参考
1. Create OperationContracts and DataContracts
2. Update your service Reference.
3. Create WCF client in your app
4. You'll get the method refernce
这篇关于我的应用程序中的WCF服务引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!