简体   繁体   中英

WCF Rest service to receive Push notification data

I have Restful WCF service which will be used to read the data push by another Restful service hosted somewhere on the internet. I have to expose one method to read the Json data push by the other service.

[ServiceContract]
public interface ITestService
{
    [OperationContract]
    [WebInvoke( Method = "GET",
        ResponseFormat = WebMessageFormat.Json )]
    string GetData(string JsonData);
}

Is it right to receive data in string parameter or should i make the DataContract (Class) to receive the Json data. I know the structure of the Json data push by other service and Is it ok to make Get Method ? Also Push service can send bulk of data at once. how can i restrict it so my server works fine even with bulk data.

I personally don't like the default JSON handling in WCF and thus we use Newtonsoft.Json! We define the data values as string and then check the incoming data versus a JSON Schema file. In my opinion it depends on how extensive you use WCF. For use we use WCF primarily for tcp connections where we use the defined Data interfaces. The REST api is just for internal debugging and not exposed. So a clearly documented api isn'T that important. By defining proper data contracts you can utilize the automated docs WCF generates under the root url of the restful service + /help.

Anyway you should NOT use an HTTP GET to receive push notifications.

POST/PUT would be an appropriate endpoint for a push notification. The following article explains quite well how and why to define REST routes the way to be:

http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#restful

Hope that helps a bit.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM