WebGet 不恰当地添加尾部斜杠
我有一个休息客户端尝试调用 http://my-server/section1/section2?param1= foo
http://my-server/section1/section2?param1=foo http://my-server/sectionX/sectionY?param2=bar http://my-server/sectionA/sectionC?param3=kuku
注意查询参数键名称更改(param1、param2、param3...)
我实现的合约是
[WebGet(UriTemplate = "")]
[OperationContract]
Message MyMethod();
但是这将导致调用的实际 uri 为: http://my-server/section1/section2/?param1=foo
请注意在section2 和? 之间添加了一个尾部斜杠。
有人知道如何预防吗?
大卫·
PS 请注意 1)将最后一个段+参数作为MyMethod的参数(并使用UriTemplate =“/ {lastSegment}”)的技巧将导致问号(?)被解码... 这会破坏呼叫请求 2) 完全删除 UriTemplate 将导致方法名成为 uri 的一部分...
I have a rest client which tries to call http://my-server/section1/section2?param1=foo
http://my-server/section1/section2?param1=foo
http://my-server/sectionX/sectionY?param2=bar
http://my-server/sectionA/sectionC?param3=kuku
notice that the query parameters key name changes (param1, param2,param3...)
The contract I implemented is
[WebGet(UriTemplate = "")]
[OperationContract]
Message MyMethod();
However this will cause the actual uri called to be:
http://my-server/section1/section2/?param1=foo
Note that a trailing slash has been added between section2 and ?
Does someone know how to prevent it?
David
PS
pls note that
1) a the trick of taking the last segment+ the parameters as a parameter to MyMethod (and usage of UriTemplate="/{lastSegment}) will cause the question mark (?) to be decoded...
which will ruin the call request
2) removing the UriTemplate completely will cause the methodname to be part of the uri...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实不应该在客户端上使用 WCF 合约来调用 REST 服务。只需使用 HTTPWebRequest 或 HttpClient 进行这些调用即可。
You really should not use WCF contracts on the client to make calls to REST services. Simply use HTTPWebRequest or HttpClient to make those calls.