Sunday, 30 April 2017

Functional programming:
It introduces a new style in programming. This is not a property of the language but this is the way to use the language.
The languages are different in degree of support of this style. Java 8 added some features to better support the functional programming such as lambda expression, stream and ...
This style of thinking and programming brings more expressive, easier to write, less error prone and easier parallelism, and makes the code more concise. It allows to the programmer to focus more on what he want instead of describing how to achieve what he wants. In traditional programming style the programmer enters in details of the steps to be passed to do something, but in functional programming there is a higher degree of abstraction that prevents the code to be too verbose.

Friday, 20 January 2017

DataContractSerializer vs XmlSerializer

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>