I would like to be able to set a property on an object via my CRUD interface by using a URL such as:
http://example.com/service/object?property=value
To that end I tried the following, which is invalid.
[WebInvoke(Method = "POST", UriTemplate = "device/{deviceID}?{propName}={propValue}")]
[OperationContract]
void SetDeviceProperty(string DeviceID, string propName, string propValue);
[WebInvoke(Method = "GET", UriTemplate = "device/{deviceID}?{propName}")]
[OperationContract]
string GetDeviceProperty(string DeviceID, string propName);
The closest example I could find was something like
propertyName={proeprtyName},propertyValue={propertyValue}
...but that would make for some ugly URLs. I'd like to keep it as simple as the object path followed by ?name=value
For the POST part it looks like it's unnecessary to create such UriTemplate you can just do it like this:
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "sendTransaction")]
SomeResponse RequestMethod(SomeRequest req);
Where SomeResponse is a class for Response and SomeRequest is the request.
For the GET part I don't think you can make it more elegant, your choice would be to make it all POST. Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.