[英]Can't execute WCF REST services for POST and GET with basic endpoint address
我正在尝试使用以下端点(以及其他端点)创建一组WCF REST服务:
以下是服务合同中的定义:
[OperationContract]
[WebInvoke(Method="POST", RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json, UriTemplate="Session")]
string InitializeSession(Stream contents);
[OperationContract]
[WebInvoke (Method="GET", RequestFormat=WebMessageFormat.Json,
ResponseFormat=WebMessageFormat.Json, UriTemplate="Session/{sid}")]
string RetrieveSession(string sid);
没有定义GET操作,我可以很好地调用POST并在响应中获取期望的sid。 包括GET OperationContract时,调用POST引发:
500 System.ServiceModel.ServiceActivationException
即使我有响应中也没有其他数据(非常有帮助)
<serviceDebug includeExceptionDetailInFaults="true"/>
在web.config的服务行为中定义。
对于我要实现的目标,OperationContract定义是否正确(假设我要实现的目标是正确的RESTful)? 如果是这样的话,那么我可能会错过关于哪个愚蠢的配置选项的任何想法,这将允许同时访问这两种操作?
Try changing your operation contracts of your get and post methods to some thing like below:
1. Post
[OperationContract]
[WebInvoke(UriTemplate = "Session", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
2. Get
[OperationContract]
[WebInvoke(UriTemplate = "Session/{sid}", Method = "GET", ResponseFormat =
WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.