15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Contracts ❘ 1293<br />

oPeraTionConTraCT ProPerTy<br />

Action<br />

ReplyAction<br />

AsyncPattern<br />

IsInitiating IsTerminating<br />

IsOneWay<br />

Name<br />

ProtectionLevel<br />

desCriPTion<br />

WCF uses the Action of the SOAP request to map it to the<br />

appropriate method. The default value for the Action is a<br />

combination of the contract XML namespace, the name of the<br />

contract, <strong>and</strong> the name of the operation. If the message is a response<br />

message, Response is added to the Action string. You can override<br />

the Action value by specifying the Action property. If you assign<br />

the value “*”, the service operation h<strong>and</strong>les all messages.<br />

Whereas Action sets the Action name of the incoming SOAP<br />

request, ReplyAction sets the Action name of the reply message.<br />

If the operation is implemented by using an asynchronous pattern,<br />

set the AsyncPattern property to true. The async pattern is<br />

discussed in Chapter 20, “Threads, Tasks, <strong>and</strong> Synchronization.”<br />

If the contract consists of a sequence of operations, the initiating<br />

operation should have the IsInitiating property assigned to<br />

it; the last operation of the sequence needs the IsTerminating<br />

property assigned. The initiating operation starts a new session; the<br />

server closes the session with the terminating operation.<br />

With the IsOneWay property set, the client does not wait for a reply<br />

message. Callers of a one-way operation have no direct way to<br />

detect a failure after sending the request message.<br />

The default name of the operation is the name of the method the<br />

operation contract is assigned to. You can change the name of<br />

the operation by applying the Name property.<br />

With the ProtectionLevel property, you define whether the<br />

message should be signed or encrypted <strong>and</strong> signed.<br />

With the service contract, you can also define the requirements that the service has from the transport with the<br />

attribute [DeliveryRequirements]. The property RequireOrderedDelivery defines that the messages<br />

sent must arrive in the same order. With the property QueuedDeliveryRequirements, you can define that<br />

the message should be sent in a disconnected mode, for example, by using Message Queuing (covered in<br />

Chapter 46).<br />

message Contract<br />

A message contract is used if complete control over the SOAP message is needed. With the message contract,<br />

you can specify what part of the message should go into the SOAP header <strong>and</strong> what belongs in the SOAP<br />

body. The following example shows a message contract for the class ProcessPersonRequestMessage.<br />

The message contract is specified with the attribute MessageContract. The header <strong>and</strong> body of the SOAP<br />

message are specified with the attributes MessageHeader <strong>and</strong> MessageBodyMember. By specifying the<br />

Position property, you can define the element order within the body. You can also specify the protection<br />

level for header <strong>and</strong> body fields.<br />

[MessageContract]<br />

public class ProcessPersonRequestMessage<br />

{<br />

[MessageHeader]<br />

public int employeeId;<br />

}<br />

[MessageBodyMember(Position=0)]<br />

public Person person;<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!