Preliminary Study on WCF-14: WCF Service Agreement, Preliminary Study on wcf-14 Protocol

Source: Internet
Author: User

Preliminary Study on WCF-14: WCF Service Agreement, Preliminary Study on wcf-14 Protocol

Preface:

  • In the previous article, the service agreement we defined had a ServiceContract feature to modify, because the implementation of the service contract was defined by ServiceContractAttribute, then, use the OperationContractAttribute attribute in one or more classes (or interfaces) to define the service operations of the agreement. When the service agreement is implemented and used together with the WCF binding and EndpointAddress object, the service agreement will be made public for the client.
  • The public information is represented by ServiceContractAttribute. Its interface is loosely related to the Web Service Description Language (WSDL) <portType> element. A service agreement can be used to publish content to the caller at a specified service endpoint. It can also be used on the client to specify the protocol for communications between the client and the endpoint

The Web Service Description Language (WSDL) Web Server Description Language is the standard for describing Web services using XML documents. It is the interface definition Language of Web Services,

Intel, IBM, and MS jointly propose that the following three basic attributes of Web services can be described through WSDL:

What do services do-operations provided by services (methods)

How to access the service-data format and necessary protocols for interaction with the service

Where the service is located-Protocol-related addresses, such as URLs

In WCF, WSDL is a data format for metadata exchange. Through its description, the WCF Service programs can exchange data accordingly, even cross-platform applications can exchange data.

Service Agreement attributes:

When ServiceContract is added to the service contract interface, we can see that it has two constructors, one with no parameters. There is also a parameter with the following:

  • Name: gets or sets the Name of the <portType> element in the Web Service Description Language (WSDL. After this name is set, the default generated proxy class is this name + Client.
  • Namespace: gets or sets the Namespace of the <portType> element in the Web Service Description Language (WSDL.
  • ConfigurationName: used to find the name of the Service Element in the application configuration file. The default value is the name of the service implementation class.
  • ProtectionLevel: Use the ProtectionLevel attribute to specify the degree to which the Protocol binding requires encryption and/or digital signatures for the end point of the public agreement. The value set here is the default value provided for all operation messages, including errors.
  • SessionMode: gets or sets whether a session is allowed, not allowed, or required. The SessionMode attribute is used to enable session binding between endpoints. A session is a way to associate a message set that is exchanged between two or more endpoints. If your service supports channel sessions, you can use the InstanceContextMode attribute to specify the relationship between your service agreement and the channel session instance. If the binding does not support sessions, an exception is thrown.
  • CallbackContract: gets or sets the callback protocol type when the protocol is a duplex protocol. Specify an interface in the CallbackContract attribute, which indicates the reverse protocol required for Bidirectional (Duplex) message exchange. This allows the client application to listen for inbound operation calls, which can be sent by the server service application independently of the client activity. A callback protocol with one-way operations indicates a call from a service that can be processed by the client.

WCFService Agreement example:

  • The solution is as follows:

  

  • Engineering Structure Description:

WcfService: a WCF Service Application. For a simple description, we will delete other code, leaving only the GetData method. The IService1.cs code is as follows:

using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.ServiceModel;using System.ServiceModel.Web;using System.Text;using System.Net.Security;namespace WcfService{    [ServiceContract(Name="WcfServiceContract",        Namespace="http://wangweimutou.WcfServiceContract",        SessionMode=SessionMode.Allowed,        ProtectionLevel=ProtectionLevel.None,        ConfigurationName="Service1")]    public interface IService1    {        [OperationContract]        string GetData(int value);    }}

The code for Service1.svc is as follows:

using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;using System.ServiceModel;using System.ServiceModel.Web;using System.Text;namespace WcfService{    public class Service1 : IService1    {        public string GetData(int value)        {            return string.Format("You entered: {0}", value);        }    }}

Click Service1.svc in the browser to view its WSDL file, because this article only focuses on the attributes of the service agreement. So we can look at WSDL as a common XML file, from which we can see some settings

The attribute of has changed. For other attribute applications, you can viewA Preliminary Study on WCF-5: Duplex Communication in the WCF message exchange mode)AndWCF preliminary study-13: the WCF client creates a callback object for the duplex ServiceTwo blog posts.

  

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.