WCF 数据服务代理没有心情两次使用相同的命名空间
我第一次为 WCF 数据服务创建代理时,代码生成器 (Visual Studio 2010 SP1) 将实体类型定义放入:
MyClient.DBService.DBModel
来自服务的 OData 源如下所示:
<element p2:type="DBModel.GetWorkstationProfile_Result">
此版本的服务仅公开 服务操作,而不是实体集。对项目的前半部分感到满意,然后我开始提供一些实体集,因此我在数据服务中为它们添加了一些访问规则,如下所示:
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("FooBars", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("GetWorkstationProfile", ServiceOperationRights.All);
我在客户端上执行了“更新服务引用”,但现在代理将所有内容放入其中,
MyClient.DBService
包括服务操作返回的复杂类型,这些类型过去位于 MyClient.DBService.DBModel 中。
但是,数据服务仍将返回元素的类型设置为 DBModel.GetWorkstationProfile_Result
,因此对象永远不会被反序列化。每次调用都会产生一个空列表,即使我可以在浏览器中检查相同的查询并看到来自服务的 OData 也很好。
我只需在数据服务的 InitializeService
方法中启用或禁用 SetEntityAccessRule
即可使代理代码生成器来回移动。禁用 - 一切都在 MyClient.DBService.DBModel
中;已启用 - 一切都在 MyClient.DBService
中进行。
这是 WCF 数据服务中的错误吗?如何说服代理代码生成器使用其原始命名空间,或让数据服务在新命名空间内传递元素?
The first time I created my proxy for a WCF Data Service, the code generator (Visual Studio 2010 SP1) put entity type definitions in:
MyClient.DBService.DBModel
And the OData feeds coming from the service looked like this:
<element p2:type="DBModel.GetWorkstationProfile_Result">
This version of the service only exposed Service Operations, not entity sets. Happy with the first half of the project, I then started to make some entity sets available, and so I added some access rules for them in the Data Service, like this:
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("FooBars", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("GetWorkstationProfile", ServiceOperationRights.All);
I did "Update Service Reference" on the client, but now the proxy puts everything into
MyClient.DBService
including the Complex Types returned by the Service Operations, and which used to go in MyClient.DBService.DBModel
.
However, the Data Service is still setting the type of returned elements to DBModel.GetWorkstationProfile_Result
and so the objects never get deserialized. Every call results in an empty list, even though I can check the same query in my browser and see the OData coming from the service just fine.
I can make the proxy code generator go back-n-forth just by enabling or disabling the SetEntityAccessRule
in the Data Service's InitializeService
method. Disabled--everything goes in MyClient.DBService.DBModel
; Enabled--everything goes in MyClient.DBService
.
Is this a bug in WCF Data Services? How can I convince either the proxy code generator to use its original namespace, or get the Data Service to deliver elements within the new namespace?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在服务器上进行了导致新命名空间的更改?
您可以尝试删除代理并从头开始创建它。
编辑
尝试:
Have you made a change on the server that results in the new namespace?
You could try deleting the proxy and creating it from scratch.
Edit
try: