标签: wcf-data-services

WCF是否需要datacontract属性?

WCF中是否需要DataContract属性?

我有一个没有用DataContract标记或没有用DataMember标记属性的类。

当我在4台服务器上部署wcf服务时,出4台服务在3台服务器上工作正常,而在1台服务器上失败,并显示消息“类型'类'无法序列化。请考虑用DataContractAttribute属性标记它,并标记要序列化的所有成员使用DataMemberAttribute属性。”

那么,web.config或machine.config或IIS中是否有任何设置可以强制我在代码中使用序列化程序?要么

如果未指定属性,我可以指定使用默认序列化程序吗?

谢谢,克里希纳

.net wcf wcf-binding wcf-data-services

0
推荐指数
1
解决办法
2709
查看次数

WCF数据服务OData; 用$ format指定JSON"verbose"的方法?

WCF数据服务根据Accept:标头更改其响应JSON格式,因此这两个标头提供不同的结果:

Accept: application/json
Accept: application/json; odata=verbose
Run Code Online (Sandbox Code Playgroud)

但是,OData规范提供了$format=应该执行相同操作的查询参数.WCF似乎尊重$format=json参数,但将其视为application/json接受标头.但我想要详细的JSON ......

所以我的问题是; 有什么可能的价值$format=?有没有办法使用它来指定详细的JSON?

(我已经知道我可以更改我的代码以使用accept标头,但现有代码使用$ format,所以我更愿意改变它.)

我正在使用预发布的WCF数据服务,v5.1.0-rc2


编辑:

我的请求看起来像这样:

网址:

http://localhost:52116/Services/MusicStore.svc/Albums?$format=json&%24inlinecount=allpages&%24filter=substringof('the'%2Ctolower(Title))
Run Code Online (Sandbox Code Playgroud)

请求标题:

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
DataServiceVersion: 3.0
Host: localhost:52116
MaxDataServiceVersion: 3.0
MinDataServiceVersion: 3.0
Proxy-Connection: keep-alive
Referer: http://localhost:52116/
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4
X-Requested-With: XMLHttpRequest
Run Code Online (Sandbox Code Playgroud)

这将返回有效的JSON(非详细).

但是,如果我尝试,$format=jsonverbose那么我从WCF获得HTTP 500,在跟踪日志中有这个:

<Exception>
<ExceptionType>System.ServiceModel.CommunicationObjectAbortedException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>The communication object, System.ServiceModel.Channels.TransportReplyChannelAcceptor+TransportReplyChannel, cannot be used for communication …
Run Code Online (Sandbox Code Playgroud)

wcf-data-services odata

0
推荐指数
1
解决办法
2828
查看次数

如何在Any子句中拆分Linq表达式

我正在尝试进行模块化Linq查询(到OData源).

这是我的查询的简化版本:

// Any clause that I want to be modular
Func<Encounter, bool> orderAnyClause = x => x.OrderName.StartsWith("Order 00");

// Query using the any clause
var result = entities.Customers.Where(cust=> cust.Orders.Any(orderAnyClause));

// A method to do the selection.  It works just fine.
IQueryable<SearchSelectionResult> selectedResults = SelectResults(result); 

// This throws the exception shown below
var list = selectedResults.ToList();  
Run Code Online (Sandbox Code Playgroud)

这一切都很好,但是当我运行它时,我的any子句会导致这个异常:

无法将类型为"System.Linq.Expressions.ConstantExpression"的对象强制转换为"System.Linq.Expressions.LambdaExpression".

我知道这是我的任何条款,因为如果我在声明中嵌入该条款,一切正常.

为什么我收到此错误?我怎么能打破这个声明而不是错误呢?


更新:使用表达式

我尝试使用这样的表达式:

Expression<Func<Encounter, bool>> orderAnyClause = 
                                      x => x.OrderName.StartsWith("Order 00");
Run Code Online (Sandbox Code Playgroud)

我收到以下编译时错误消息:

Instance argument: cannot convert from System.Data.Services.Client.DataServiceCollection<ODataComponetizedQueriesTest.MyEntities.Order>' to 'System.Linq.IQueryable<ODataComponetizedQueriesTest.MyEntities.Order>'
Run Code Online (Sandbox Code Playgroud)

.net c# linq wcf-data-services odata

0
推荐指数
1
解决办法
538
查看次数

WCF数据服务抛出"操作可能会破坏运行时的稳定性"异常

我的目标是通过IIS将SQL Server 2008表公开为XML/JSON.

我按照几个(1) 视频(2)来展示WCF数据服务Web应用程序,当$ metadata页面工作时,尝试查看实际数据会导致异常:

Operation could destabilize the runtime.
System.Security.VerificationException
Run Code Online (Sandbox Code Playgroud)

截图

我从这个带有.NET 4.5.1和Entity Framework 6.1.2的VS2013 模板开始- 下面是更具体的软件包版本.

如果NuGet包导致VerificationException,我应该尝试删除所有NuGet包,并只添加EntityFramework(以及依赖的任何东西)?

欣赏任何想法,谢谢你们!

Id                             Version              Description/Release Notes                                                                                              
--                             -------              -------------------------                                                                                              
Antlr                          3.5.0.2              ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, in...
bootstrap                      3.3.2                Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.                 
EntityFramework                6.1.2                Entity Framework is Microsoft's recommended data access technology for new applications.                               
jQuery …
Run Code Online (Sandbox Code Playgroud)

.net asp.net-mvc wcf entity-framework wcf-data-services

0
推荐指数
1
解决办法
1082
查看次数