Generate sample data for REST services for WCF?

Is there a way to generate an XML / JSON sample based on the WCF REST interface? In most cases, devices that consume our web services deserialize the message to the appropriate object. However, sometimes this is not possible, and so I need to send the developers the actual XML / JSON that they need to provide to the services and what the output looks like. Is there an easy way to generate this information, even if it uses default values ​​for data types?

Example webservice interface:

[OperationContract] [WebGet(UriTemplate = "Test", ResponseFormat = WebMessageFormat.Xml)] ResultOfAction Test(); // used to login [OperationContract] [WebInvoke(UriTemplate = "Login?", Method = "POST", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)] ResultOfAction Login(LoginRequest request); // register a client + forgot password [OperationContract] [WebInvoke(UriTemplate = "RequestOTP?", Method = "POST", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)] ResultOfAction RequestOTP(RequestOneTimePIN requestOneTimePin); 

In the above example, I will need to see the XML file ResultOfAction, LoginRequest and RequestOneTimePIN. Is there an easy way to create such information?

+4
source share
1 answer

When the helpEnabled="true" attribute is set in the configuration, WCF 4.0 will generate sample data based on the format that you return from the service method call:

 <behaviors> <endpointBehaviors> <behavior name="webHttpBehavior"> <webHttp helpEnabled="true"/> </behavior> </endpointBehaviors> </behaviors> 

Here is an example from MSDN.

+4
source

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


All Articles