Brief description of WCF, WebService, Socket

Source: Internet
Author: User

1, WCF has an ABC, simply say what is ABC? What is the WCF full name? Windows Communication Foundation (WCF) is a set of data communication application development interfaces developed by Microsoft that can be translated into Windows communication interfaces
In the WCF framework, the communication between the various application is implemented by endpoint. Endpoints is the core element of WCF's implementation of communication
WCF supports protocols such as Http,tcp,named Pipe,msmq,peer-to-peer TCP, the most basic communication mechanism is the SOAP (Simple Object access Protocol the easy Objects accessing protocol), This ensures interoperability between systems, even when running in a different context


Address:address uniquely identifies a endpoint through a URI and tells the caller of a potential WCF service how to find the endpoint (port) (endpoint consists of three parts: address, Binding (protocol binding), contract (contract))

The binding implements all the underlying details of the client and service communication. For example, the message passed between the client and service is how to encode the--text/xml, binary,mtom; What kind of transport--tcp is used, Http, Named Pipe, MSMQ;
Only if the client has a Endpoint that exactly matches the service, can we invoke the service

How many


contracts are there? What they do.
in WCF, the contract is divided into four types:
The service that defines the service operation WCF contract: Service contract
This level of contract also includes two kinds: ServiceContract and OperationContract
ServiceContract for classes or structs, to indicate that WCF such or struct can be called remotely, Instead, OperationContract is used on methods in the class to instruct WCF that the method can be called remotely.
data for a custom structure the WCF contract: the data Contract
database contract is also divided into two types: DataContract and DataMember
DataContract is used on a class or struct to instruct WCF that such a class or struct can be serialized and transmitted, whereas DataMember can only be used on a class or struct property or field, indicating that WCF is capable of serializing the property or field.
exception for custom error exceptions WCF contract: Fault contract
Faultcontract is used to handle custom error exceptions by default when the server throws an exception. The client can receive the description of the exception information, but these descriptions tend to be uniform in format, sometimes more difficult to obtain useful information, at this time, we can customize the format of the exception message, the message we care about in the error message to pass to the client, at this time need to add a custom error message class on the method, Then add faultcontract to the function that will handle the exception and return the exception information to the custom format.
A message that controls the message format WCF contract: Message contract
Simply put, it can customize the message format, including the message header, the body of the message, and also indicate whether the message content is encrypted and signed.

WCF supports multiple communication protocols Http/https, TCP/UDP, MSMQ, named pipes, peer network, message accessibility, transaction flow, and more
WCF can integrate with ASP, share a context (HttpContext),
WS can also be integrated with ASP, but cannot share a context (HttpContext),
WCF supports a variety of message transmission formats: Text,binary,mtom,json, and so on.
WCF supports multiple session modes: one-way, two-way, request/response.
WCF supports rest.
WCF is more configurable than WS, such as security
WCF can be stateful and supports transactions.

Sockets: Often also referred to as "sockets", applications usually make requests to the network via "sockets" or respond to network requests, with the principle of communication:
Service side:
1, create the socket object, to listen to the port, and let the client to connect
2. Bind a port and IP
3. Start listening port
4, start to accept the client connection, after connecting with the client
5, with the client to send and receive messages
6. Close socket
Client:
1. Create a Socket object
2, a server on the network to a certain port to make a request to the server, connected to the server side, with the service side after the connection
3, with the server to send and receive messages
4. Close socket

What is WebService?
Web Service is a platform-independent, programmable Web-based application that exposes an external
The web makes a call to the API that is used to develop distributed interop applications.

Under what circumstances should you use a Web service.
A perfect solution to the client-server communication problem is to use the HTTP protocol to communicate.
Whatever the platform and programming language of the two programs.
Because any machine running a Web browser is using the HTTP protocol. At the same time, many firewalls are currently configured to allow only HTTP connections.

What is the difference between sockets and WebService?
Sockets are system-level things that can accomplish communication between TCP,UDP and other protocols.
Websevice is an application-level thing and a specification for using the socket + HTTP protocol.

Sockets are used to implement the network layer. Each layer needs our own implementation in the program.
For example, the port can define itself, the definition of the packet, the encryption and decryption of the packet, etc.

And webservice implements the application layer of the tool, he based on the service is the HTTP protocol, through the server can be published.
So the definition of the internal port, the definition of the packet, and the encryption and decryption of the packet are all done, so we can use it directly.
The WebService internal data format is XML format and is not affected by firewalls because of HTTP-based protocols.
Because his communication agreement is the same as the one we browse the Web.

WebService principle:
Here we will publish the Web service machine called the server side, and the machine calling the Web service is called the client.
First the server will publish the Web service.
Client Invoke steps:
Step 1: Join the Web App to join the Web service you just published, then generate a proxy for the Web service in the local, we assume that WebProxy.
Step 2: The client invokes the object of the agent before it is called, and then calls the published method
Step 3: The client adds the invocation information including the method name and parameters to the SOAP message and sends it over HTTP to the Web service server.
Step 4: The server obtains the invocation information from the SOAP message, then executes the method, adds the returned result to the SOAP message, and then passes the HTTP back
Step 5: The client agent gets this SOAP message after parsing the result back to the calling client method

Two kinds of verification methods under WebService,
I. Integration with Windows authentication
By integrating Windows to solve WebService security issues is a very concise, and effective solution, the advantages of the scheme is relatively safe, good performance, of course, because with Windows tightly together, the shortcomings are naturally obvious, first, not easy to transplant, second, To make the relevant configuration deployment work (of course, we can also use code to operate IIS, but it is more troublesome, recently has been doing automated deployment, so the configuration will immediately associate with how to automatically deploy)
How do you do it specifically?
Server-side: Configure IIS Virtual directories for Integrated Windows authentication
Client:
Service1 WR = new Service1 (); Web Service Instance
Url Credentials = new NetworkCredential ("Administrator", "123"); User name password
Lbltest.text = WR. ADD (2,2). ToString (); Call the Add Web service method
Two. Using SoapHeader (SOAP header) to customize the authentication
SoapHeader most of the circumstances used to pass the user authentication information, of course, its role is far more than that, to be explored in the actual application, the body can achieve what things people have ideas to communicate with the message.
SoapHeader Steps to use:
(1) Create a custom SoapHeader type that inherits from System.Web.WebServices.SoapHeader.
(2) Create a custom soapheader field in WebService that has public access.
(3) Add the Soapheaderattribute Access feature on WebMethod that need to use SoapHeader. The Soapheaderattribute construct must specify the MemberName parameter, which is the name of the field we declared in the second step.
(4) The generator automatically generates custom SoapHeader types for the client with the same name, but is more complex than what we created on the WebService side. A Soapheadervalue property is also added for the proxy type

Brief description of WCF, WebService, Socket

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.