Programming core content 2: Communication and programming core communication

Source: Internet
Author: User

Programming core content 2: Communication and programming core communication

WCF is a communication management framework provided by. NET with high flexibility.

I. Features

1. Flexible server support:Asp.net, windows Service, com + process, windows form, etc.

2. Convenient programming:Common base classes are not required.

3. Optional channels:Http, tcp, ipc, and custom channel.

4. Security:Supports the wse 3.0 standard.

5. scalability: Soap injection.

6. Integration: Supports integration of dcom and asp.net web Services.

Ii. Core Services

1. Simple SOAP Object Access Protocol

2. WSDL Web Service Description Language

3. Transmission of representative REST states

4. JSON JavaScript Object Tag

3. Custom Service host

1. inherit from System. ServiceModel. ServiceHost

2. instance. Open () Start listener Channel

3. Close () to Close the service.

4. Use the WCF Service Configuration Editor tool to edit the WCF Configuration file

Iv. Client

1. Add a service reference (the Service uses the Mexican httpbinding to bind the MEX endpoint)

2. Add System. Runtime. Serialization, System. ServiceModel Assembly reference, and the configuration file for binding information and endpoints.

3. Generate a proxy class and an object class. The object class contains the elements marked by [DataMember ].

V. Diagnosis

You can use the Service Configuration Editor tool for Configuration. Use Service Trace Viewer(svctraceviewer.exe) to view the Trace file.

Vi. Agreements

1. Data protocols [DataMember]:. Name field Name. Order serialization sequence. IsRequired optionality. EmitDefaultValue default value: serialization

2. Data version [DataContract]:. Namespace xml Namespace (to delete a field and add a required field, modify the Namespace to distinguish different versions)

3. Service Agreement [ServiceContract]:Service Interface. ConfigurationName service configuration Name. CallbackContract duplex communication client. Name <portType> Name. Namespce <portType> namespace. SessionMode session type. ProtectionLevel protection communication type

4. Operational agreement [OperationContract]:. Action request link. By default, it is a combination of xml namespace, protocol name, operation name, and Response type (ending with Response. replyAction response link. asyncPattern asynchronous link. isInitiating the initial session. isTeminating ends the session. isOneWay has no response operation. name operation Name. protectionLevel security type

5. Transfer Agreement :[DeliveryRequirements], [RequireOrderedDelivery], and [QueuedDeliveryRequirements]

6. Message protocols :[MessageContract], [MessageHeader], and [MessageBodyMember]

VII. Implementation Service 1. [ServiceBehavior] annotation implementation class:

. TransactionAutoCompleteOnSessionClose session type. transactionIsolationLevel transaction isolation level. when the ReleaseServiceInstanceOnTransactionComplete session is completed. the shuticsessionshutdown session is disabled. instanceContexMode object status. concurrencyMode concurrency. useSynchronizationContext window thread. includeExceptionDetailInFaults exception handling. the number of serialized objects in MaxItemsInObjectGraph. validateMustUnderstand understand the title

2. Implement the Service Interface 3. [OperationBehavior]:

The. AutoDisposeParameters parameter is automatically released. The Impersonation caller runs. ReleaseInstanceMode lifecycle. TransactionScopeRequired transaction. TransactionAutoComplete automatically completes the transaction.

8. Programming client 1. Example of ChannelFactory class:

Var binding = new WSHttpBinding ();

Var address = new EndpointAddress (Link );

Var factory = new ChannelFactory <I service> (binding, address );

I service channel = factory. CreateChannel ();

Factory. Close ();

2. Add service reference in visual studio 3. ServiceModel metadata plugin tool (svcutil.exe) to generate a proxy class:

Var client = new XXServiceClient ();

Client. RegisterForCourse (...);

Client. Close ();

4. Duplex Communication

The specified protocol interface must be implemented on the client.

Server:

Public interface IMyMessageCallback {

[OperationContract (IsOneWay = true)]

Void OnCallback (string message );}

[ServiceContract (CallbackContract = typeof (IMyMessageCallback)]

Public interface IMyMessage {

[OperationContract]

Void MessageToServer (string message );}

Client:

Class ClientCallback: IMyMessageCallback {

Public void OnCallback (string message ){}}

 

9. Exception Handling

1. [FaultContract] indicates the exception data class associated with the operation

2. Throw a FaultException <exception data class>

10. Bind

Binding describes the communication mode of the service. Including: transmission protocol, security, encoding format, transaction stream, reliability, shape change, and transmission upgrade.

Pre-defined binding:

By function:

 

11. Message Queue

Message Queue is an important auxiliary tool for communication tasks. The System. Messaging space encapsulates the Message Queue read/write function of the windows operating System.

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.