2015-07-28 47 views
0

我有一个需要字符串参数的方法的WCF Rest-Service。这个参数是一个Uri。为了能够使用URI作为REST服务的参数,我使用了JavaScript方法encodeURIComponent方法来编码URI如何使用URI参数调用WCF REST服务

http://creativeartefact.org/example/fa9eb3e7-8297-4541-81ec-e9e9be6e6638 

变得

http%3A%2F%2Fcreativeartefact.org%2Fexample%2Ffa9eb3e7-8297-4541-81ec-e9e9be6e6638 

当我调用服务以正常字符串,一切都很好

../liveEvents/qwertz 

当我用编码的Uri(我直接在浏览器中输入请求)调用它时,我得到一个“no en dpoint发现“错误。

../liveEvents/http%3A%2F%2Fcreativeartefact.org%2Fexample%2Ffa9eb3e7-8297-4541-81ec-e9e9be6e6638 

任何想法可能是什么问题以及如何安全地将URI作为参数传递给WCF使用JavaScript的REST服务?

由于提前,
弗兰克

编辑:这是端点法:

[OperationContract] 
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "liveEvents/{artistUri}")] 
IList<LiveEvent> GetLiveEventsList(string artistUri); 

回答

0

只要不使用UriTemplates。 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 

另外,无需编码这里。

0

传递URL作为查询字符串参数。 假设你的Get方法的签名是这样的:

Get(string id) 

的你只是用这个网址拨打:

'/liveEvents/?id=' + encodeURIComponent('http://test.com/?name=Foo&id=2') 

希望它可以帮助

+0

我在问题中添加了方法签名。使用?artistUri =没有帮助。即使使用/?artistUri = qwertz的测试请求现在也会失败,并显示“找不到端点”错误。 – Aaginor

+0

所以,基于你的问题,你的GetLiveEventsList方法响应Get动词。 您可以使用http:// yourdns/liveEvents /?artistUri = qwertz调用在浏览器中打开的方法吗?它工作吗? –

+0

不,这不起作用。我得到了Endpoint-not-found-error – Aaginor