/*by garcon1986*/
1. What is WCF and how it works?
Windows Communication Foundation is a framework for intercommunication between different applications regardless of their languages.
Example:
IHelloWorldService.cs:
using System.Runtime.Serialization; //used for DataContract.
using System.ServiceModel; //used for ServiceContract.
//it contains the types necessary to build Windows Communication Foundation (WCF) service and client applications.
namespace MyWCFServices
{
[ServiceContract]
public interface IHelloWorldService
{
[OperationContract]
string GetMessage(string name);
[OperationContract]
string GetPersonCompleteInfo(Person person);
}
//DataContract is used to be transmitted between web service and client
[DataContract]
public class Person
{
[DataMember]
public int Age { get; set; }
[DataMember]
public string Sex { get; set; }
[DataMember]
public string Name { get; set; }
}
}
HelloWorldService.cs:
/// <summary>
/// Create a service class and implement service interface
/// </summary>
public class HelloWorldService : IHelloWorldService
{
public string GetMessage(string name)
{
return "Hello world from " + name + "!";
}
public string GetPersonCompleteInfo(Person compInfo)
{
return "Person complete info( age is:" + compInfo.Age + ";sex is:" + compInfo.Sex + ";name is:" + compInfo.Name + ")";
}
}
2. WCF vs ASMX web service:
AXMX web service is just add WebMethod attribute to methods.
Example:
[WebMethod]
public string MyMethod(string text)
{
return "Hello" + text;
}
WCF use interface , the class implements interface which provide encapsulation and security.
3. WCF binding types:
BasicHttpBinding is designed to replace ASMX Web services. It supports both HTTP and Secure HTTP. As far as encoding is concerned, it provides support for Text as well as MTOM encoding methods. BasicHttpBinding doesn’t support WS-* standards like WS-Addressing, WS-Security and WS-ReliableMessaging.
WsHttpBinding also supports interoperability. With this binding, the SOAP message is, by default, encrypted. It supports HTTP and HTTPS. In terms of encoding, it provides support for Text as well as MTOM encoding methods. It supports WS-* standards like WS-Addressing, WS-Security and WS-ReliableMessaging. By default, reliable sessions are disabled because it can cause a bit of performance overhead.
reference:
http://www.codeproject.com/Articles/431291/WCF-Services-Choosing-the-appropriate-WCF-binding
4. EndPoint
<endpoint address="http://localhost:8080/HostDevServer/HelloWorldService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHelloWorldService"
contract="HelloWorldService.IHelloWorldService" name="WSHttpBinding_IHelloWorldService">
<identity>
<userPrincipalName value="username" />
</identity>
</endpoint>
ABC: Address, Binding, Contract