WCF Restful service GET / POST

Can I do something like this?

[OperationContract] [WebInvoke ( Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/abc{integerParam}" ) ] ResultStruct abc( int integerParam, CustomClass secondParam ); 

The idea is that I can pass the first parameter (integer) in the url and secondParam from POST. Is it possible?

I started with WCF REST and did not know how parameters are assigned. Any pointers will be helpful to you.

+6
source share
1 answer

Yes, you can here, RESTful Web Services Design and Creation Guide

 [ServiceContract] public partial class BookmarkService { [WebInvoke(Method = "PUT", UriTemplate = "users/{username}")] [OperationContract] void PutUserAccount(string username, User user) {...} [WebInvoke(Method = "DELETE", UriTemplate = "users/{username}")] [OperationContract] void DeleteUserAccount(string username) {...} [WebInvoke(Method = "POST", UriTemplate = "users/{username}/bookmarks")] [OperationContract] void PostBookmark(string username, Bookmark newValue) {...} [WebInvoke(Method = "PUT", UriTemplate = "users/{username}/bookmarks/{id")] [OperationContract] void PutBookmark(string username, string id, Bookmark bm) {...} [WebInvoke(Method = "DELETE", UriTemplate = "users/{username}/bookmarks/{id}")] [OperationContract] void DeleteBookmark(string username, string id) {...} ... } 

For me, such a RESTful web service design is terrible. This ServiceContrcat:

  • unsupported , fragile remote interface
  • Too many methods to create.
  • No polymorphism

I believe that the remote interface should be stable and flexible , we can use a message-based approach to design web services.

A detailed explanation can be found here: Creating RESTful Message Based Web Services with WCF , Code Samples Here: Nelibur and Nelibur nuget Package Here

+21
source

Source: https://habr.com/ru/post/921696/


All Articles