joi, 8 octombrie 2009

[WCF] [ServiceContract]/[OperationContract]

To influence the service contract, the [ServiceContract] attribute has several parameters that have their own functions:
CallbackContract: Gets or sets the type of callback contract. This is useful when using the duplex messaging exchange pattern.
ConfigurationName: Defines the name as used in the configuration file to store the related configuration settings.
Name: Gets or sets the name for the element in WSDL. The default value is the name of the .NET interface.
Namespace: Gets or sets the namespace for the element in WSDL. The default value is the namespace of the .NET interface.
HasProtectionLevel: Defines a (read-only) value that indicates the protection level of the service. At the operation level, it is possible to define that the messages of the operation must be encrypted, signed, or both.
ProtectionLevel: Defines the protection level that the binding must support.
SessionMode: Gets or sets a value that defines whether the contract requires the WCF binding associated with the contract to use channel sessions. SessionMode is an enumeration with possible values of allowed, notallowed, and required. The default value is allowed.
_______

The same is true for the [OperationContract] attribute. Several parameters are available
to you:
Name: Specifies the name of the operation. The default is the name of the operation.
Action: Defines the (WS-Addressing) action of the request message.
AsyncPattern: Indicates that the operation is implemented asynchronously by using a egin/End method pair.
IsInitiating: Defines a value that indicates whether the method implements an operation that can initiate a session on the server.
IsOneWay: Defines a value that indicates whether an operation returns a reply message. IsTerminating: Defines a value that indicates whether the operation causes the server to close the session after the reply message is sent.
ProtectionLevel: Defines a value that indicates the protection level of the operation. You can define that the messages of the operation must be encrypted, signed, or both.
ReplyAction: Defines the value of the SOAP action for the reply message of the operation.

_____________
[DataContract]
-> you can also annotate your custom types with the [Serializable]
-> you have to specifically annotate each property with the [DataMember] attribute (even is public or private one).

[DataContract] attribute has several parameters that have their own functions:
Name: Defines the name for the data contract, which will also be the name in the XML schema (XSD, WSDL). The default value is the name you defined in .NET.
Namespace: Defines the namespace for the data contract. Use this property to specify a particular namespace if your type must return data that complies with a specific data contract or XML schema.

Several parameters for the [DataMember] attribute:
Name: Defines the name for the data contract, which will also be the name in an XML schema (XSD, WSDL). The default value is the name you defined in .NET.
Namespace: Defines the namespace for the data contract. Use this property to specify a particular namespace if your type must return data that complies with a specific data contract or XML schema.
IsRequired: Gets or sets a value that instructs the serialization engine that the member must be present.
Order: Gets or sets the order of serialization and deserialization of a member. This can be important if clients rely on the order of the fields.
EmitDefaultValue: Gets or sets a value that specifies whether to generate a default value of null or 0 for a field or property being serialized.

Niciun comentariu:

Trimiteți un comentariu