标签:
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using SilverlightWCF.DAL; namespace SilverlightWCFServices { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IWorkerInfoService”。 [ServiceContract] public interface IWorkerInfoService { [OperationContract] [ServiceKnownType(typeof(WorkerInfo))] List<WorkerInfo> getWorkerInfo(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; using sil.DAL; using sil.BLL; using System.ServiceModel.Activation; namespace sil.Services { // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“WorkerService”。 // 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 WorkerService.svc 或 WorkerService.svc.cs,然后开始调试。 //[ServiceBehavior(IncludeExceptionDetailInFaults = true)] //[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class WorkerService : IWorkerService { public List<WorkerInfo> getAllWorker() { return new BLL_Worker().getAllWorker(); } } }
<?xml version="1.0" encoding="utf-8" ?> <access-policy> <cross-domain-access> <policy> <allow-from http-request-headers="*"> <domain uri="*"/> </allow-from> <grant-to> <resource path="/" include-subpaths="true"/> </grant-to> </policy> </cross-domain-access> </access-policy>
导入命名空间
using SilverlightWCFClient.WorkerInfoServiceReference;
代码示例:
public void getWorkerInfo() { WorkerInfoServiceClient client = new WorkerInfoServiceClient(); client.getWorkerInfoCompleted += client_getWorkerInfoCompleted; //vs版本不同,这行代码会有所差异 client.getWorkerInfoAsync(); } void client_getWorkerInfoCompleted(object sender, getWorkerInfoCompletedEventArgs e) { if (e.Error != null) return; if (e.Result.Count > 0) { dgWorkerInfo.ItemsSource = e.Result.ToList(); } }
标签:
原文地址:http://www.cnblogs.com/phantom-k/p/5518038.html