作为WCF数据服务查询字符串一部分的电子邮件地址

本文关键字:一部分 电子邮件地址 字符串 查询 WCF 数据 服务 作为 | 更新日期: 2023-09-27 18:17:37

我定义了一个WCF REST服务操作如下:

  [OperationContract]
  [WebInvoke(UriTemplate = "/findcomplaints/{applicationkey}/{culture}/{maxNumberOfComplaints}/{emailaddress}/{categoryid}/{onlymarkedasabusive}/{sortkey}/{pagenumber}", Method = "GET", ResponseFormat = WebMessageFormat.Json)]
  FindComplaintsResponse FindComplaints(string applicationKey, string culture, string maxNumberOfComplaints, string emailAddress, string categoryId, string onlyMarkedAsAbusive, string sortKey, string pageNumber);

我想用fiddler测试这个,但是我不知道如何在查询字符串中传递电子邮件地址。如果我在fiddler:

中尝试这个
  http://localhost:55708/ComplaintService.svc/findcomplaints/code/nl-BE/5/email@hotmail.com/1/1/sortkey/1

然后我得到错误'资源无法找到'(因为'email@hotmail.com'部分,因为如果我用常规字符串替换它,我没有得到错误)。

知道如何在这个uri中传递电子邮件吗?

编辑:我也试图用%40转义@符号,但得到了相同的错误。事实上,@不会引起任何问题。似乎是这个点导致了错误。但是为什么呢?

编辑2:如果我使用?语法如http://localhost:55708/ComplaintService.svc/findcomplaints?email=email@hotmail.com没有问题。

谢谢

作为WCF数据服务查询字符串一部分的电子邮件地址

如果服务托管在Visual Studio Development Server(即所谓的Cassini)上,那么当URI包含多个点字符时可能会出现问题。这是开发服务器的一个已知限制。要解决这个问题,请使用IIS Express或完整的IIS。

您需要在URL中对'@'符号进行URL编码,以便它不会被错误地解析。

http://www.w3schools.com/tags/ref_urlencode.asp