保护ADO.NET数据服务的最佳方法是什么?有没有人在生产中使用过这个,如果有的话你用过什么安全选项?
我有一个实体,其字段为int类型
我希望将这些字段公开为获取和接收枚举类型值以进行强类型操作的属性.
所以我为实体创建了一个新的分部类,并添加了两个属性.
当我尝试创建TestEntity的新实例并将其添加到上下文,并调用保存更改时,我得到以下异常:
处理此请求时发生错误.在System.Data.Services.Client.DataServiceContext.SaveAsyncResult.HandleBatchResponse()在System.Data.Services.Client.DataServiceContext.SaveAsyncResult.EndRequest()在System.Data.Services.Client.DataServiceContext.SaveChanges(SaveChangesOptions选项)在系统.Data.Services.Client.DataServiceContext.SaveChanges()
内在的例外是:
System.InvalidOperationException:类型'enum1'没有可设置的属性.在System.Data.Services.Client.ClientType..ctor(类型type,字符串的typeName,布尔skipSettableCheck)在System.Data.Services.Client.ClientType.Create(类型类型,布尔expectModelType)在System.Data.Services.Client在System.Data.Services.Client.DataServiceContext.CreateRequestData(ResourceBox框,布尔换行)在System.Data.Services.Client.DataServiceContext.SaveAsyncResult.CreateChangeData .DataServiceContext.WriteContentProperties(XmlWriter的作家,ClientType类型,对象资源)(的Int32索引System.Data.Services.Client.DataServiceContext.SaveAsyncResult.BeginNextChange(Boolean replaceOnUpdate)中的布尔换行符
所以我想它试图将枚举属性反映为类属性.如何在上下文中尝试反映它们时忽略这些属性.
我正在使用VS 2008团队套件sp1,SQL Server 2008,.Net 3.5 Sp1.
救命.
部分类代码:
public partial class TestEntity
{
public enum1 Field1
{
get
{
return (enum1)field1;
}
set
{
field1 = (Int16)value;
}
}
public enum2 Field2
{
get
{
return (enum2)field2;
}
set
{
field2 = (Int16)value;
}
}
}
Run Code Online (Sandbox Code Playgroud) 对于一个项目,我必须在Web服务器上托管的数据库和互联网上的几个客户端之间实现通信.在阅读了一些内容并观看了一些关于可能(微软)技术的介绍性视频后,我发现我似乎有(至少)三种选择:
1)Windows Communication Foundation(WCF)
2)ASP.NET Web服务
3)ADO.NET数据服务
因为我不熟悉这三种技术中的任何一种,我必须深入学习(希望只有)其中一种技术 - 问题是:哪一种?
或者更确切地说:哪一个用于以下任务?
需要将数据从客户端上载到服务器/数据库,并且还需要下载一些其他数据.在客户端,这不会由在浏览器中工作的用户以交互方式发生,而是作为客户端上的自动进程定期运行(例如每2小时).
a)在Web服务器端,将有:
b)客户方不太清楚,必须更灵活.在这里,我必须区分两个要求:
i)优先级一(根据我可用于开发的时间):
ii)优先级较低,但必须是未来选项:
由于最后一点迫使开发人员在客户端使用.NET Framework不是一种选择.客户端的通信必须是可从各种平台和语言访问的任何"标准"技术.在我的小研究中,我正在阅读"SOAP","REST"或"AtomPub"等术语,这些似乎是一种标准协议或通信技术(不是微软的专有发明).但我不确定也不知道哪种技术是"最新的",具有"最佳未来",是最常见和众所周知的,是最强大的还是最容易使用的(从其他可能的角度来看)开发人员!问题是我必须支持哪些让大多数客户端开发人员满意.
最后一点:安全很重要!上传/下载数据必须限于专职人员.没有适当的凭证,就不可能使用或探索界面.
什么技术现在最好用?(1),(2)或(3)?你为什么推荐它?
非常感谢您的任何建议!
我想使用LINQ和Data Services返回一组实体,这些实体具有包含在ID列表或数组中的ID和ID.我知道如何使用LinqToEF,但我不知道如何使用Data Services或使用OData查询约定.
我的想法是我会做类似的事情:
int[] intArray = {321456, 321355, 218994, 189232};
var query = (from data in context.Entity
where intArray.contains(data.ID)
select data);
Run Code Online (Sandbox Code Playgroud)
有没有办法使用Data Services/OData?我知道我可能会通过服务操作破解它,但我宁愿不这样做.
干杯.
我试图从我的WCF数据服务返回一个自定义类.我的自定义类是:
[DataServiceKey("ID")]
public class Applist {
public int ID { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的数据服务看起来像:
public static void InitializeService(IDataServiceConfiguration config)
{
config.RegisterKnownType(typeof(Applist));
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("GetApplications", ServiceOperationRights.AllRead);
}
[WebGet]
public IQueryable<Applist> GetApplications() {
var result = (from p in this.CurrentDataSource.Applications
orderby p.ApplicationName
group p by p.ApplicationName into g
select new Applist { ID = g.Min(p => p.id), Name = g.Key });
return result.AsQueryable();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行该服务时,它给了我一个错误:
Request Error Request Error The server encountered an error …Run Code Online (Sandbox Code Playgroud) 我有一个通过ADO.net Data Services与数据库交互的项目.数据库很大(几乎150个表具有依赖性).该项目于几年前启动,当时使用的是DataSet; 现在我们正朝着实体模型关系迈进.由于我们要添加更多需要使用的表,因此该模型正在增长.这是管理所有这些的正确方法吗?我应该有一个SINGLE数据库模型文件来拥有单个数据上下文吗?
有什么缺点,如何将实体框架与大型数据库一起使用(或者不应该与大型数据库一起使用?
我看到的缺点是:
PS,奇怪,没有人回答.这个问题看起来很重要,用简单的话来说,我只是改写一下:哪个更好,一个整体,一个大型数据库的模型或该数据库的几个模型?
我在LINQ to SQL数据上下文之上做一个简单的WCF数据服务.我的svc.cs文件非常简单.但是,当我从VS2012运行它时,我得到一个通用的"请求错误",没有更多的信息.我该如何排除故障/解决它?
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using MyApp.Business.Pmw.DataAccess;
namespace MyApp.DataService
{
public class SystemData : DataService<PmwModelDataContext>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("SysParam", EntitySetRights.ReadMultiple);
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
// config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
// config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我变了
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3
Run Code Online (Sandbox Code Playgroud)
从V3到V2验证JSON输出是否为Verbose.但是,当我将其更改回V3时,输出仍然是详细的,我必须添加
?$format=application/json;odata=verbose
Run Code Online (Sandbox Code Playgroud)
为了获得JSON Light.有关如何将其恢复到正确版本的提示?
我有一个覆盖的WCF DataService(v5.2)OnStartProcessingRequest(ProcessRequestArgs args).我想在响应中添加一些标题(在这种方法中我假设它是正确的位置?).我第一次尝试这个:
args.OperationContext.ResponseHeaders.Add(...)
Run Code Online (Sandbox Code Playgroud)
那没用.然后我尝试了这个:
OperationContext.Current.OutgoingMessageHeaders.Add(...)
Run Code Online (Sandbox Code Playgroud)
那没用.我尝试在那个吸盘上添加一个新的OperationContextScope.它仍然失败了.最后我尝试了这个:
HttpContext.Current.Response.AddHeader(...);
Run Code Online (Sandbox Code Playgroud)
那个选项有效!(通过"工作"我的意思是它实际上出现在对客户的响应中.)为什么前两个选项不起作用?
在网上进一步阅读后,我发现了这一点
WebOperationContext.Current.OutgoingResponse.Headers.Add(...)
Run Code Online (Sandbox Code Playgroud)
也有效.为什么我们在这个方法中有四个当前的上下文?一个人如何知道使用哪一个(在运行时)?哪些在我的[WebGet]方法中有效?哪些在我的[QueryInterceptor]方法中有效?哪个上下文保证有正确的请求标头?(我现在一直在使用args.OperationContext.)
我目前正在使用带有Entity Framework的WCF数据服务(以及ADO.Net数据服务),并且在执行POST时出现以下错误(省略/更改了一些不相关的信息):
<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code /><m:message xml:lang="en-GB">The URI 'http://localhost:56568/MyWcfDataServices.svc/EntitySetName(pk_id)' is not valid for POST operation. For POST operations, the URI must refer to a service operation or an entity set.</m:message></m:error>
Run Code Online (Sandbox Code Playgroud)
在网上浏览一下,我似乎无法找到有关此消息的大量信息,因此调试它有点困难.这可能是因为我发布的一个属性是一个很大的base64字符串(如果我不发布它,它可以正常工作).我试过设置maxRequestLength如下:
<httpRuntime maxRequestLength="102400" />
Run Code Online (Sandbox Code Playgroud)
但它似乎没有帮助.虽然我会继续解决这个问题,但我想我会在这里做一个快速的帖子,看看是否有人知道可能会有所帮助的事情.
我的WCF数据服务类如下所示:
public class MyWcfDataServices: DataService<ContextName>
{
public static void InitializeService(DataServiceConfiguration config)
{
// set entity access rules etc
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢
编辑:我似乎没有得到这个.这是我到目前为止所尝试的内容.
在服务器端,我设置了以下绑定:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
minFreeMemoryPercentageToActivateService="0" />
<services>
<service name="MyWcfDataServices"
behaviorConfiguration="myBehaviorConfig">
<endpoint address=""
binding="webHttpBinding"
bindingConfiguration=""
contract="System.Data.Services.IRequestHandler" />
</service>
</services>
<behaviors> …Run Code Online (Sandbox Code Playgroud) c# ×6
.net-3.5 ×1
asp.net ×1
database ×1
datacontext ×1
http-headers ×1
linq ×1
return-type ×1
security ×1
wcf ×1
web-services ×1