Problem:
The default serializer of WCF; DataContractSerializer; does not create attributes. It just makes elements. To be able to create the attributes, you must direct WCF to use XmlSerializer.
How: You must add [XmlSerializer] Under [ServiceContract]. Then specify the member is to be an attribute by [DataMember, XmlAttribute].
Example:
to create the following message
<?xml version="1.0" encoding="UTF-8"?>
<Product id="89471">
<Name>
Printer
</Name>
</Product>
[ServiceContract]
[XmlSerializer]
public class Product
{
[DataMember, XmlAttribute]
public string id;
public string Name{get;set;}
}
Problem: This works with GET method but on POST method it returns a response saying the request is not correct.
Solution: When you set XmlSerializer, the request content must be sent in xml format. For example, a method that takes a string parameter would be called like:
<?xml version="1.0" encoding="UTF-8"?><string>John</string>
No comments:
Post a Comment