0

So I have a URL to my wcf service that looks like this:

http://dev.verse-master.com/api/VerseMasterService.svc/Search/bi/isaiah 34:16/0/60

My operation contract looks like this:

[OperationContract]
[WebGet(UriTemplate = "/Search/{translation}/{searchTerm}/{skip}/{take}", ResponseFormat = WebMessageFormat.Json)]
VerseMaster.BusinessLayer.DataObjects.ServerObjects.GetVersesSearchServerObject GetVersesBySearch(string translation, string searchTerm, string skip, string take);

I have tried from reading online to add this line to the web.config:

<httpRuntime requestPathInvalidCharacters="" requestValidationMode="4.0"/>

But I still get this error:

HTTP Error 400 - Bad Request.

Any ideas?

4

1 回答 1

0

对 url 进行编码,应该没问题,只需在返回时处理它。这也将有助于反斜杠,这将导致与以下相同数量的问题:

例如

调用服务:

String encodedSearchTerm = Server.UrlEncode(searchTerm);
String UrlToCall = String.Format("{0}{1}{2}","http://dev.verse-master.com/api/VerseMasterService.svc/Search/bi/",encodedSearchTerm,"/0/60");

...ETC...

然后在您的操作中:

[WebGet(UriTemplate = "/Search/{translation}/{searchTerm}/{skip}/{take}", ResponseFormat = WebMessageFormat.Json)] 
VerseMaster.BusinessLayer.DataObjects.ServerObjects.GetVersesSearchServerObject GetVersesBySearch(string translation, string searchTerm, string skip, string take){
...etc...
String DecodedSearchTerm= Server.UrlDecode(searchTerm);
...etc...
}

记得需要导入System.Web

于 2012-06-01T06:54:52.423 回答