使用从客户端库调用的参数的 ADO.Net 服务服务操作失败 [英] ADO.Net Services service operation with parameters called from client library fails
本文介绍了使用从客户端库调用的参数的 ADO.Net 服务服务操作失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
控制台应用
var result = dataService.CreateQuery<Customers>("GetCustomerByLastName").
AddQueryOption("lastname", "S");
服务
[WebGet]
public IQueryable<Customers> GetCustomerByLastName( string lastname )
{
return from c in this.CurrentDataSource.Customers
where c.LastName.StartsWith( lastname )
select c ;
}
结果:(相对于 http://localhost:1478/Apress.Data.Services.CustomerService.Host/)
RequestUri:CustomerDataService.svc/GetCustomerByLastName()?lastname=S
RequestUri: CustomerDataService.svc/GetCustomerByLastName()?lastname=S
结果失败了,因为 uri 中的括号是意料之外的.
and fails as a result , because of parentheses in uri , which are not expected.
CustomerDataService.svc/GetCustomerByLastName?lastname='S'
CustomerDataService.svc/GetCustomerByLastName?lastname='S'
在浏览器中工作.
VS 2008 SP1.
VS 2008 SP1 .
推荐答案
原来问题与括号无关,我缺少字符串文字单引号
It turned out the problem was not related to parentheses , I was missing string literal single quotes
应该是
AddQueryOption("lastname", "'S'");
但是
GetCustomerByLastName()?lastname='S'
和
GetCustomerByLastName?lastname='S'
两者都适用于 ADO.Net 数据服务.
both correct for ADO.Net Data Services.
这篇关于使用从客户端库调用的参数的 ADO.Net 服务服务操作失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文