locked
Deserializing WebInvoke Service Operation Response RRS feed

  • Question

  • I know there is no support for calling the service operations with http method other than 'GET'. I'm using HttpWebRequest to call the service and I'm able to read the response stream, which contains an entity object serialed in odata xml format. Is there any built-in functionallity I can use to deserialize it?
    Tuesday, June 7, 2011 1:02 PM

Answers

  • You will need to manually consume the XML data returned by the HttpWebReponse from a request to a POST service operation, maybe by using XDocument (XLinq).

    I've just published a simple example of how to do this in a new blog post:

    Calling Service Operations Using POST

    Cheers!

    Glenn Gailey


    Please visit my blog

    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by GStoyanov Thursday, June 9, 2011 7:29 AM
    Wednesday, June 8, 2011 4:49 PM

All replies

  • First off, there is actually support for POST service ops, you declare then with [WebInvoke(Method = "POST")].

    That aside, for GET service ops that returns an entity feed, you can actually materialize it using the client side library - DataServiceContext.Execute<T>(Uri) should give you back an IEnumerable of T.

    Regards,

    PQ


    Peter Q. http://blogs.msdn.com/peter_qian
    Tuesday, June 7, 2011 6:13 PM
    Answerer
  • You can find more information and examples of calling GET service operations using the WCF Data Services client library here: http://msdn.microsoft.com/en-us/library/hh230677.aspx

    Cheers,

    Glenn Gailey


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, June 8, 2011 1:25 AM
  • @Peter Qian

    Maybe I didn't make myself clear enough. I never said there is no support for declaring POST service operations. I said there is no support for calling POST service operations. I know how to declare service operation with [WebInvoke] - I already have and my question is about how to materialize the response of that service operation. I am not interest in calling GET service operations.

    Regards,

    GStoyanov

    Wednesday, June 8, 2011 7:46 AM
  •  

    @Glen Gailey

    Sorry, I was actually looking for information on calling a service operation declared with WebInvoke, in other words, not using http GET. Actually, I am already calling it using HttpWebRequest (is there support for anything else?). I'm looking for a way to materialze the response.

    Regards,
    GStoyanov

    Wednesday, June 8, 2011 7:53 AM
  • You will need to manually consume the XML data returned by the HttpWebReponse from a request to a POST service operation, maybe by using XDocument (XLinq).

    I've just published a simple example of how to do this in a new blog post:

    Calling Service Operations Using POST

    Cheers!

    Glenn Gailey


    Please visit my blog

    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by GStoyanov Thursday, June 9, 2011 7:29 AM
    Wednesday, June 8, 2011 4:49 PM
  • @Glen Gailey

    Hi! Thanks for your answer. I suspected this to be the case, since everything in the client library that is concerned with materializing the response is internal, but I hoped I had missed something.

    Parsing an IEnumerable<string> is trivial. However, I was more concerned with parsing a response that contains an entity object or IEnumerable of entities. Parsing this response this response would be trivial as well. However, this will make the code more brittle by introducing unnecessary couplings to the way odata serializes objects as xml, the actual structure of the entity and the format of the response - xml/json - a change to any of this will require a change in the parser. What I was hoping for was a class like DataContractODataXmlSerialzer that will abstract away the details of the parsing and will reduce the coupling of the code.

    Thanks again.

    Regards,

    GStoyanov

    Thursday, June 9, 2011 7:29 AM
  • I the future, I wouldn't be surprised to see components that can handle this kind of OData serialization. However, for now, I would try to use a WebGet method whenever possible, since then at least you can have the client do this deserilzation of (Atom/XML) entities in the response. Of course, the client currently doesn't handle JSON at all.

    Cheers,

    Glenn Gailey


    Please visit my blog

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, June 9, 2011 11:31 AM