簡體   English   中英

無法使用基本端點地址為POST和GET執行WCF REST服務

[英]Can't execute WCF REST services for POST and GET with basic endpoint address

我正在嘗試使用以下端點(以及其他端點)創建一組WCF REST服務:

  • / Session (支持HTTP POST並創建一個Session對象。在響應中返回sid)
  • / Session / {sid} (支持HTTP GET,並返回代表先前創建的Session的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)]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM