C# Can';t使用基本端点地址为POST和GET执行WCF REST服务
我正在尝试创建一组具有以下端点(以及其他端点)的WCF REST服务:C# Can';t使用基本端点地址为POST和GET执行WCF REST服务,c#,web-services,wcf,rest,C#,Web Services,Wcf,Rest,我正在尝试创建一组具有以下端点(以及其他端点)的WCF REST服务: /Session(支持HTTP POST并创建会话对象。在响应中返回sid) /Session/{sid}(支持HTTP GET并返回表示先前创建的会话的JSON对象) 以下是服务合同中的定义: [OperationContract] [WebInvoke(Method="POST", RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat
- /Session(支持HTTP POST并创建会话对象。在响应中返回sid)
- /Session/{sid}(支持HTTP GET并返回表示先前创建的会话的JSON对象)
[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)]