req:wcf服务和asp.net 4.0(选择,插入,删除,更新)操作 [英] req:wcf service and asp.net 4.0 (slect,insert,delete,update) operations

查看:56
本文介绍了req:wcf服务和asp.net 4.0(选择,插入,删除,更新)操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,专家,
我是wcf的初学者,我想使用linq to sql或ado.net实体模型开发wcf服务,需要在asp.net Web应用程序中使用它,任何机构都可以解释或向我发送演练或任何示例. br/>
提前谢谢.
prasad

Hi Experts,
I am beginner to wcf and i want to develop wcf service with the linq to sql or ado.net entity model , which need to be consume in asp.net webapplication, can any body explain or send me the walk through or any example.

Thanks in advance.
prasad

推荐答案

让我们从dbml文件开始(我们需要在其中添加连接)
在dbml文件中,我们需要在左侧添加来自服务器资源管理器表的连接,并在右侧添加存储过程.


添加服务参考以及.svc文件中的任何更改,并且在服务客户端扩展上,请更新服务参考.

在服务文件(.svc)中,我们需要编写为给定应用程序执行所需的所有功能

< OperationContract()> _
公共函数GetPublicHolidays(employeeID作为字符串,StartDate作为日期)作为列表(员工)
昏暗的db作为新的DataConnectivityDataContext
暗淡q =(从db.employees中的e中,其中e.employee_id =公司ID e.holiday_date> = StartDate选择e).ToList
db.Dispose()
返回q

最终功能

然后在主页类中调用该函数
请注意:我正在使用异步功能,因此,如果您正在使用异步功能,请先安装Async CTP 3.0(对于silvelight 4和5),然后添加这两个dll's
AsyncCTPLibrary_Silvelight.dll
AsyncCTPLibrary.dll

私有异步函数GetemplyeeData(employee_id作为字符串,StDate作为日期)作为Task(Of ObservableCollection(Of projectname.ServiceReference1.employees))
Dim svc =新项目名称.ServiceReference1.ShiftRosteringServiceClient()

昏暗的t1 = MyServiceClientExtensions.GetemployeeAsyncHelper(svc,employeeID,StDate)

等待t1
昏暗s = t1.Result

返回s
最终功能

在MyServiceClientExtensions中添加辅助功能,如下所示:

公共函数GetEmployeeAsyncHelper(客户端为projectname.ServiceReference1.ShiftRosteringServiceClient,_
EmployeeID作为字符串,StartDate作为日期)作为Task(Of ObservableCollection(Of projectname.ServiceReference1.employees))

昏暗的taskCompletion =新的TaskCompletionSource(Of ObservableCollection(Of projectname.ServiceReference1.employees))()

AddHandler client.getemployeesCompleted,Sub(s,e)
如果e.[Error]不为空,则taskCompletion.TrySetException(e.[Error])ElseIf e.Cancelled则taskCompletion.TrySetCanceled()其他taskCompletion.TrySetResult(e.Result)如果If
,则结束 结束子

client.getemployeeAsync(employeeID,StartDate)
返回taskCompletion.Task

结束功能
let''s start from dbml file(where we need to add the connections)
In dbml file we need to add connections from server explorer tables will be on left side and stored procedures will be on right hand side.


add the service Reference and any change in .svc file and on service client extensions please update service Reference.

In service file (.svc) we need to write all the functions required to execute for a given application

<OperationContract()> _
Public Function GetPublicHolidays(employeeID As String, StartDate As Date) As List(Of employees)
Dim db As New DataConnectivityDataContext
Dim q = (From e In db.employees Where e.employee_id = companyID e.holiday_date >= StartDate Select e).ToList
db.Dispose()
Return q

End Function

then in mainpage class call that function
please note:I am using async function so if you are using async function first install Async CTP 3.0 (for silvelight 4 and 5 )then add these two dll''s
AsyncCTPLibrary_Silvelight.dll
AsyncCTPLibrary.dll

Private Async Function GetemplyeeData(employee_id As String, StDate As Date) As Task(Of ObservableCollection(Of projectname.ServiceReference1.employees))
Dim svc = New projectname.ServiceReference1.ShiftRosteringServiceClient()

Dim t1 = MyServiceClientExtensions.GetemployeeAsyncHelper(svc, employeeID, StDate)

Await t1
Dim s = t1.Result

Return s
End Function

in MyServiceClientExtensions add helper fuction like this:

Public Function GetEmployeeAsyncHelper(client As projectname.ServiceReference1.ShiftRosteringServiceClient, _
EmployeeID As String, StartDate As Date) As Task(Of ObservableCollection(Of projectname.ServiceReference1.employees))

Dim taskCompletion = New TaskCompletionSource(Of ObservableCollection(Of projectname.ServiceReference1.employees))()

AddHandler client.getemployeesCompleted, Sub(s, e)
If e.[Error] IsNot Nothing Then taskCompletion.TrySetException(e.[Error]) ElseIf e.Cancelled Then taskCompletion.TrySetCanceled() Else taskCompletion.TrySetResult(e.Result) End If
End Sub

client.getemployeeAsync(employeeID, StartDate)
Return taskCompletion.Task

End Function


这篇关于req:wcf服务和asp.net 4.0(选择,插入,删除,更新)操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆