这里已经提出了类似的问题:
使用从客户端库调用的参数的 ADO.Net Services 服务操作失败
问题的整个描述与我现在的相同。唯一不同的是我以正确的方式传递所有参数。
我在数据服务中定义了此操作方法:
[WebGet]
public IQueryable<Equipment> GetCompanyEquips(int id)
{
return this.CurrentDataSource.GetCompanyEquips(id);
}
并且我可以在网络浏览器中毫无问题地从中获取结果:
http://localhost:51685/ITSServiceOData.svc/GetCompanyEquips?id=18
但是,当我尝试在客户端中获取这样的结果时:
var r = this.CreateQuery<Equipment>("GetCompanyEquips");
r.AddQueryOption("id", CompanyId);
r.ToArray();
我遇到以下异常:
“发生错误处理这个请求。”
我还在调试器中看到 r.Query = "{http://localhost:51685/ITSServiceOData.svc/ GetCompanyEquips}”,我怀疑这里出了问题,因为我在末尾没有看到 ?id=18 。
另外,当我调用这样的方法时:
this.Execute("http://localhost:51685 /ITSServiceOData.svc/GetCompanyEquips?id=18") - 返回包含空枚举(尽管在本例中未引发异常),但当我在浏览器中调用相同的查询字符串时,它会显示预期结果。
另外,当我以类似的方式调用没有任何参数的方法时,一切都工作正常。请帮忙!我花了一整天的时间来解决这个问题,在互联网上搜索蚂蚁试图解决这个问题,但没有发现我的代码有任何问题!
谢谢。
The similar quetion already was asked here :
ADO.Net Services service operation with parameters called from client library fails
The whole description of problem the ame as I have now. Only thing diffrent is what I pass all parameters in right way.
I have this opertaion method defined in data service:
[WebGet]
public IQueryable<Equipment> GetCompanyEquips(int id)
{
return this.CurrentDataSource.GetCompanyEquips(id);
}
And I can get result from it without any problem in my web browser:
http://localhost:51685/ITSServiceOData.svc/GetCompanyEquips?id=18
But when I' mtrying to get result in my client like this:
var r = this.CreateQuery<Equipment>("GetCompanyEquips");
r.AddQueryOption("id", CompanyId);
r.ToArray();
I have following exception:
"An error occurred while processing this request."
Also I see in debugger what r.Query = "{http://localhost:51685/ITSServiceOData.svc/GetCompanyEquips}" and I suspect that something wrong here, because I don't see ?id=18 at the end here.
Also when I invoke method like this:
this.Execute("http://localhost:51685/ITSServiceOData.svc/GetCompanyEquips?id=18") - return contains empty enumeration (though in this case exception not raised) but when I invoke the same query string in browser it show expected result.
Also when I invoke in the similar way Method which haven't any params - all work fine. Please help! I've spent one whole day for this problem by searching in internet ant trying solve the issue but didn't find nothing wrong with my code!
Thanks.
发布评论
评论(1)
AddQueryOption 方法返回 IQueryable 的新实例。因此,您需要修改代码来执行以下操作:
另一件事:客户端库不支持读取对返回原始或复杂类型枚举的服务操作的响应。因此,要使其正常工作,设备类型必须是实体类型。
The AddQueryOption method returns a new instance of IQueryable. So you need to modify your code to do:
One other thing: The client library does not support reading responses to service operations returning enumeration of primitive or complex types. So for this to work the Equipment type must be an entity type.