如何使用URI参数调用WCF REST-Service
How to call WCF REST-Service with URI parameter
我有一个WCF Rest-Service,它的方法需要字符串参数。该参数是一个Uri。为了能够使用URI作为REST服务的参数,我使用JavaScript方法encodeURIComponent对URI
进行编码http://creativeartefact.org/example/fa9eb3e7-8297-4541-81ec-e9e9be6e6638
是
http%3A%2F%2Fcreativeartefact.org%2Fexample%2Ffa9eb3e7-8297-4541-81ec-e9e9be6e6638
当我用一个正常的字符串调用服务时,一切正常
../liveEvents/qwertz
当我用编码的Uri调用它时(我直接在浏览器中输入请求),我得到一个"没有找到端点"的错误。
../liveEvents/http%3A%2F%2Fcreativeartefact.org%2Fexample%2Ffa9eb3e7-8297-4541-81ec-e9e9be6e6638
任何想法可能是什么问题,以及如何安全地传递一个URI作为参数与JavaScript的WCF REST服务?
提前感谢,
弗兰克。
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "liveEvents/{artistUri}")]
IList<LiveEvent> GetLiveEventsList(string artistUri);
传递url作为查询字符串参数。假设您的Get方法签名是这样的:
Get(string id)
你只需调用这个url:
'/liveEvents/?id=' + encodeURIComponent('http://test.com/?name=Foo&id=2')
希望有所帮助
就是不要使用uritemplate。WCF没有它们也可以工作,当从JavaScript调用时,它们不会产生差异(据我所知)。
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
IList<LiveEvent> GetLiveEventsList(string artistUri);
像这样调用服务:
http://theserver.com/Service.svc/GetLiveEventsList?artistUri=http://creativeartefact.org/example/fa9eb3e7-8297-4541-81ec-e9e9be6e6638
相关文章:
- consume salesforce chatter rest service from pure javascript
- windows 8 wcf web service (localhost/intranet)
- WCF Restful Service (Windows Auth) with JSONP
- AngularJS service with Java (REST)?
- 调用REST Service save()方法时,XPages Dojo Grid可编辑单元格不保存值
- Nodejs rest service
- 需要经过身份验证的 WCF REST 体系结构建议
- 向WCF Rest Service发送JSON-对象文件为null
- 如何将Json post请求从java脚本发送到apache CXF Rest Service
- 使用wcf-Restful Service将json对象检索为querystring
- 无法获取属性'appendChild'WCF Rest中的未定义引用或null引用
- 从JavaScript中使用XML WCF REST web服务
- 将复合类型从JS发送到WCF REST服务
- 不允许使用自托管WCF REST服务JSON POST方法
- WCF REST服务返回JSONP,没有错误,但也没有数据
- 通过剑道UI (Javascript/Jquery)将日期传递给WCF REST服务
- 如何使用URI参数调用WCF REST-Service
- 将WCF REST服务添加到使用HTML5,Javascript,CSS开发的移动应用程序中
- 通过Ajax和JSON调用WCF REST服务
- Jquery无法从WCF REST服务获得响应