Reputation: 1930
Is there some way to generate sample XML/JSON based on a WCF REST interface? Most of the time the devices that consume our web services deserialize the message into it's relevant object. However some times that is not possible and as such I need to send developers the actual XML/JSON that they need to give to the services and what the output looks like. Is there an easy way to generate this information, even if it it uses the datatypes default values?
An example of a 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 example above, I would need to see the ResultOfAction, LoginRequest and RequestOneTimePIN serialzed XML. Is there a simple way of generating such info?
Upvotes: 4
Views: 1255
Reputation: 3945
When the helpEnabled="true"
attribute is set in the config, WCF 4.0 will generate sample data based on the format you are returning from the service method call:
<behaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
Here's an example from MSDN.
Upvotes: 4