Results 1 to 2 of 2

Thread: Spring.NET REST Client issue

  1. #1
    Join Date
    May 2011
    Posts
    1

    Default Spring.NET REST Client issue

    Hi Everybody,
    I'm currently working on a dev project that comprises both a client part (ASP.NET 3.5) and a Server part (WCF & NHIBERNATE). The client app talks to the service using REST but I'm getting a lot of problem when Posting.

    -I've got this Entity:

    Code:
    namespace Adecco.SGICC.Model
    {
        [DataContract(Name = "Platform", Namespace = "http://Adecco.SGICC.Model")]
        public class Platform : StatedEntityBase
        {
            [DataMember]
            public virtual string Description { get; set; }
    
            [DataMember]
            public virtual string Name { get; set; }
    
            [DataMember]
            public virtual string Code { get; set; }
    
            public Platform() { }
    
            public Platform(int id) 
            {
                this.Id = id;
            }
        }
    }
    -I've got this method on the client application:

    public int SavePlatform(Platform platform)

    that ends up doing something like this:

    Code:
    RestTemplate myRestTemplate = new RestTemplate();
    myRestTemplate.PostForObject<T>(uri, content);
    -After executing PostForObject, I get the following exception:

    "Could not write request: no suitable HttpMessageConverter found for part type [Adecco.SGICC.Model.Platform]"

    -In the SavePlatform(Platform platform) I use a DataContractHttpMessageConverter and add the Platforms' type to it as a SupportedMediaType like this:
    Code:
    foreach (KeyValuePair<string, object> item in content)
    {
        Spring.Http.MediaType mediaType = new Spring.Http.MediaType(item.Value.GetType().Name);
        if (!myIHttpMessageConverter.SupportedMediaTypes.Contains(mediaType))
        {
            myIHttpMessageConverter.SupportedMediaTypes.Add(mediaType);
        }
    }
    And it still keeps throwing the same exception...
    Does anybody here know what the heck I'm doing wrong here?!?!

    Thanks a lot!!!

    fretwio
    Last edited by Bruno Baia; 05-06-2011 at 08:39 AM. Reason: Added code tag

  2. #2
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,409

    Default

    Hi,

    From documentation :
    http://www.springframework.net/rest/...sageconverters

    The default converter instances registered with the template, depending of the target Framework, are ByteArrayHttpMessageConverter, StringHttpMessageConverter, FormHttpMessageConverter, XmlDocumentHttpMessageConverter, XElementHttpMessageConverter, Atom10FeedHttpMessageConverter and Rss20FeedHttpMessageConverter.
    You can override these defaults using the MessageConverters property. This is required if you want to use the XmlSerializableHttpMessageConverter/DataContractHttpMessageConverter or JsonHttpMessageConverter/NJsonHttpMessageConverter.
    So you have to add the DataContractHttpMessageConverter to the RestTemplate's message converters :
    Code:
    RestTemplate myRestTemplate = new RestTemplate();
    myRestTemplate.MessageConverters.Add(new DataContractHttpMessageConverter());
    myRestTemplate.PostForObject<string>(uri, new Platform());

    HTH,
    Bruno
    Last edited by Bruno Baia; 05-06-2011 at 08:44 AM.
    My english is as poor as my taylor is rich

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •