Knowledge Conclusion-part vi: WCF

Source: Internet
Author: User

/* By garcon1986 */

 

 

1. What is WCF and how it works?

Windows Communication Foundation is a framework for intercommunication between different applications regardless of their versions.

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

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.