WCF REST - How can client consume WebGet method which has custom object as input parameter?
-
Friday, June 27, 2008 4:25 PMHi,
I am new to REST programming. I have existing WCF service and now I am trying to implement REST. Signature of existing WCF method is :
[OperationContract]
Post GetPassedObjectPostAsXml(PostRequest request);
I want to Implement GET for the above method. I tried to decorate it with [WebGet] attribute but in UriTemplate it doesn't allow objects.
Thanks,
Mitesh
All Replies
-
Friday, June 27, 2008 5:29 PMModerator
Hi Mitesh,
AFAIK you have to rewrite the operational signature in order to allow the use of [WebGet]. Since you have not described the content of PostRequest I am unable to help you with it - but basically you have to "expand" the content of PostRequest over separate input parameters to the GetPasswdObjectPostAsXml() operation.
Ex.
[OperationalContract]
[WebGet(UriTemplate = "/posts/{postId}")]
Post GetPassedObjectPostAsXml(int postId)
{
// ...
return new Post { /* ... */ };
}
Good luck,
--larsw -
Friday, June 27, 2008 8:12 PMModerator
SInce this object can be large, you may instead want to send this data via POST data. This would normally be done with a WebInvoke and a POST or PUT as the verb. Then you can pass this object as xml through the request. -
Monday, July 07, 2008 2:23 PMyou need to have reference to System.ServiceModel.Web first in order to use WebGet attribute.
Hope this webblog help you http://dotnetninja.wordpress.com/2008/05/02/rest-service-with-wcf-and-json/ -
Monday, July 07, 2008 5:06 PM
If you use the WebScriptEnablingBehavior on your endpoint, you can have complex types passed as GET query string parameters - you'll need to serialize the complex type with JSON (instead of XML).
However, you should consider the previous suggestions to either using POST to send data to the service, or breaking up the PostRequest in atomic (primitive) members. REST recommends using POST to send complex data to a service.

