我试图通过Silverlight验证对WCF DataServices服务的调用.实质上,当用户登录时,他们会获得一个特殊的哈希值,该哈希值应该嵌入到WCF DataServices的每个请求的头文件中.目前通过QueryInterceptor方法将其用作检查,例如
[QueryInterceptor("Orders")]
public Expression<Func<Orders,bool>> OnQueryOrders()
{
string hash = WebOperationContext.Current.IncomingRequest.Headers.Get("MyHeader");
if(!TestHash(hash))
{
return o => false;
}
else
{
return o => true;
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎是实现这一目标的最糟糕方式.在运行查询之前,WCF Dataservices中是否有任何钩子可用于取消请求?请记住,此服务是无状态的,无法访问会话.
我正在使用Silverlight 4.0(所以我需要调用异步并且不能直接使用EF)和WCF数据服务以及EF 4来建模数据库.我想进行一次调用并填充几个级别的属性.
假设我有以下设置(但这可能更深入):帐户 - 拥有零个或多个客户(和其他属性) - 客户拥有零个或多个地址(和其他属性)
我想带回1个有效负载,其中Accounts,Customers和Addresses都是急切加载并包含在那个有效负载中.
我想得到:Accounts.Expand("Customers").其中(a => a.Id == 1); 这将返回帐户和客户填充的有效内容.如何在同一个呼叫中包含地址?
我用WPF客户端创建了一个非常简单的.NET 4.0 Web项目。
该Web解决方案具有WCF数据服务,该服务的服务操作返回IQueryable<string>。
WPF客户端引用该服务,CreateQuery()并.Take()直接在查询上直接调用该服务操作。
不幸的是,我收到以下错误消息:
Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource.
Run Code Online (Sandbox Code Playgroud)
如果使用http://localhost:20789/WcfDataService1.svc/GetStrings()?$top=3,在浏览器中查看服务,则会出现相同的错误。
有任何想法吗 ?让我知道是否需要将解决方案上传到某个地方。
谢谢!
WcfDataService1.svc.cs:
namespace WPFTestApplication1
{
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class WcfDataService1 : DataService<DummyDataSource>
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
[WebGet]
public IQueryable<string> GetStrings()
{
var strings = new string[]
{
"aa",
"bb",
"cc",
"dd",
"ee",
"ff",
"gg",
"hh",
"ii",
"jj", …Run Code Online (Sandbox Code Playgroud) 假设我在Netflix OData端点上有以下查询:
Titles.Where(x=>x.AverageRating > 3.0)
Run Code Online (Sandbox Code Playgroud)
有没有办法用来.IncludeTotalCount()获得符合where子句的标题数量?(不是Titles资源中项目的总数.)
我查看了这里提供的代码:http://msdn.microsoft.com/en-us/library/ee474390.aspx
但它似乎不适用于where子句.
我对Web浏览器的基本身份验证有点困惑.我原以为Web浏览器只会在上一个响应中收到HTTP 401状态后发送Authorization标头.但是,Chrome似乎会随后向每个请求发送Authorization标头.它有一次我输入的数据,以响应我网站上的401,并随每条消息一起发送(根据Chrome和我的网络服务器附带的开发人员工具).这是预期的行为吗?是否有一些标题我应该用我的401来推断授权的东西不应该被缓存?我目前正在使用WWW-Authenticate标头.
iis basic-authentication http-headers wcf-data-services http-status-code-401
我试图在Silverlight 5应用程序/ .NET 4.0应用程序中使用WCF数据服务.当我手动查询服务时,我可以在Web浏览器中看到Atom提要的数据.
但是,当我尝试通过标准方法查询数据时,我收到以下错误:
{System.Security.SecurityException:安全错误.位于System.Data.Services.Client.Hespse上的System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)(IAsyncResult asyncResult),System.Data.Services.Client.QueryResult.AsyncEndGetResponse(IAsyncResult asyncResult)上的IAsyncResult asyncResult
内部异常为空.所以目前还没有有意义的信息.
public partial class ProjectWindow : ChildWindow
{
XYZEntitis.XYZEntitis db = new XYZEntitis.XYZEntitis(new Uri("http://google.com/wcfdataservice1.svc/"));
DataServiceCollection<XYZEntitis.Label> dscCats = new DataServiceCollection<XYZEntitis.Label>();
CollectionViewSource customerAddressViewSource;
ObservableCollection<XYZEntitis.Label> labelsBindingCollection = new ObservableCollection<XYZEntitis.Label>();
public ProjectWindow()
{
InitializeComponent();
btnBack.IsEnabled = false;
//Load Project categories
BindProjectCategories();
}
public void BindProjectCategories()
{
#region Code
//#############################################
//Approach # 01 : Raises Security Exception
//#############################################
//DataServiceQuery<XYZEntitis.Label> query = db.Labels;
//query.BeginExecute(
// s =>
// {
// var state = s.AsyncState …Run Code Online (Sandbox Code Playgroud) 我使用本教程使用Visual Studio 2012配置并构建了WCF和oData.
所以我使用Firefox REST Client插件来测试它是否正常工作.
这是我的基本URL处理json, 192.168.1.4/TestdataService/TestDataService.svc/User?$format=json
我可以成功完成GET操作.但是我无法执行POST,PUT和DELETE操作.
POST操作说
状态代码:415不支持的媒体类型
它的响应体是
{
"odata.error": {
"code": "",
"message": {
"lang": "en-US",
"value": "Unsupported media type requested."
}
}
}
Run Code Online (Sandbox Code Playgroud)
PUT&DELETE运营说
状态代码:405方法
不允许允许:GET,POST
它的响应体是
{
"odata.error": {
"code": "",
"message": {
"lang": "en-US",
"value": "The URI 'http://192.168.1.4/TestdataService/TestDataService.svc/User?$format=json' is not valid for DELETE operation. The URI must refer to a single resource from an …Run Code Online (Sandbox Code Playgroud) 我在尝试过滤数据时遇到问题,因为breeze在URL的末尾添加了$ filter子句,而WCF\odata服务正在抛出过滤器,不能在select子句之后.
public IQueryable<order> Orders()
{
string owner= Membership.GetUser(Thread.CurrentPrincipal.Identity.Name).owner;
IQueryable<Consigne> q = this.db.Consignes
// .AddQueryOption("Dest", dest)
.Where(x => x.Owner == owner)
.Select(f => new order{ Name= f.Name, Address1 = f.Address1, Address2 = f.Address2, Address3 = f.Address3 });
return q;
}
Run Code Online (Sandbox Code Playgroud)
我已经使用服务器端Where子句限制结果集,并使用Select投影限制字段.如果我删除这些并让微风完全控制Where\Select然后我吹我的安全模型允许js代码控制.
我意识到这不是一个真正的微风问题而是更多的odata问题,但其他人如何处理这个?你是放弃iQueryable而只是创建一个webapi并传回json?如果是这样,那么我正在重新发明轮子,因为我还需要处理skip\take和orderby.
感谢建议:)亲切的问候,迈克
解决了
我发现WCF无法在不丢失TotalCount的情况下作为iQueryable传递.WCF返回一个QueryOperationResponse,我可以将其传递给breeze,但是一旦通过微风转换为对象,我就无法在Breeze的QueryHelper.WrapResults中找到将动态类型转换回可用对象以检索扩展的TotalCount属性.
QueryHelper将执行查询
queryResult = Enumerable.ToList((dynamic)queryResult)
Run Code Online (Sandbox Code Playgroud)
但
request.Properties.TryGetValue("MS_InlineCount", out tmp)
Run Code Online (Sandbox Code Playgroud)
由于错误的底层对象而失败.
我的解决方案是在我的BreezeController中执行查询,并将行和TotalCount包装在一个数组中,就像Breeze一样.然后我可以将数组作为类型QueryResult传回,breeze将序列化为JSON到客户端.
public QueryResult Consignees(string filter, int skip, int take)
{
WcfService.Context context = new WcfService.Context(new System.Uri(System.Configuration.ConfigurationManager.AppSettings["URI"]));
//Main Table
System.Data.Services.Client.DataServiceQuery<WcfService.Consigne> qMain = context.Consignes.IncludeTotalCount();
//Projected Table
System.Data.Services.Client.DataServiceQuery<Consigne> qProj …Run Code Online (Sandbox Code Playgroud) 我想在我的应用程序中将 WCF 与 RESTful 结合使用。
但我想之前使用任何可用的在线服务进行测试。
有没有在线部署WCF RESTful服务?
如果可用,请提供链接。
谢谢马杜
我有一个采用字节数组的数据服务.然后我有一个网页,试图将文件发送到该数据服务.如果文件很小(比如说50kb)那么一切都按预期运行,但是如果文件很大(任何超过100kb),我会在数据服务的保存更改调用上收到"BadRequest"错误消息.
有没有办法让更大的数据大小传递给数据服务?
编辑(更多细节):我已经设置了更高的maxRequestLength并尝试了一些webHttpBinding来增加maxReceivedMessageSize,但这些似乎并没有帮助.