I have to PUT a customer object from android client to the database through Restful service (.Net)
Service Contract
[WebInvoke(Method = "PUT", UriTemplate = "customers/{customerId}", RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
[OperationContract]
ReturnValueLong PutCustomer(string customerId, Customer entity);
Customer.cs
public class Customer
{
[DataMember]
public long SystemId{ get; set; }
[DataMember]
public long CustomerId { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Description { get; set; }
}
On the client side I'm using Spring for Android to communicate.
Client Code:
Customer customer = new Customer();
customer.setCustomerId(12);
customer.setName("sample name");
customer.setDescription("sample description");
customer.setSystemId(123);
List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
acceptableMediaTypes.add(MediaType.APPLICATION_XML);
// Prepare header
HttpHeaders headers = new HttpHeaders();
headers.setAccept(acceptableMediaTypes);
// Pass the new person and header
HttpEntity<Customer> entity = new HttpEntity<Customer>(
customer, headers);
final String url = "https://192.168.2.119:8009/IAdministratorService/customers/{customerId}";
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(
new SimpleXmlHttpConverter());
ResponseEntity<NCheckReturnValue> result = restTemplate
.exchange(url, HttpMethod.PUT, entity,
NCheckReturnValue.class, 12);
return "Return Code:" + result.getBody().getCode()
+ " Return Value: "
+ result.getBody().getReturnValue();
Customer.java
@Root(name = "Customer")
@Namespace(reference = "NCheck.Core.Model")
public class Customer {
@Element
private long SystemId;
@Element
private long CustomerId;
@Element
private String Name;
@Element
private String Description;
// Getters and Setters
}
When I execute the code the Customer object not received properly on the Server side. (Name is correct but the Description is null)
What is the wrong with this implementation?