[英]WCF 4.0 - Get Parameter from URL or POST Body
I have a WCF endpoint and I have setup my URI Template as such: 我有一个WCF端点,我已经设置了我的URI模板:
UriTemplate = "?token={token}"
If the token parameter is not in the URL, I want it to attempt to pull it from the POST body. 如果token参数不在URL中,我希望它尝试从POST主体中提取它。
I am testing my POST calls and putting the token in the URL works great, but fails if I put it in the POST body instead. 我正在测试我的POST调用,并且将令牌放在URL中工作得很好,但是如果我把它放在POST主体中则会失败。
Is there any way to handle this? 有办法处理这个吗? I was doing it before using a ServiceAuthorizationManager, however, there wasn't a great way to send back friendly error messages. 我在使用ServiceAuthorizationManager之前就这样做了,但是,没有一种很好的方法来发回友好的错误消息。
You can get access to the RequestBody as shown below: 您可以访问RequestBody,如下所示:
OperationContext.Current.RequestContext.RequestMessage.GetBody<string>();
Hope that helps you :) 希望能帮到你:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.