Friday, April 23, 2010

Contract first WCF tips

Generate types from xsd using WSCF Blue with options set to correct capitalisation.

On the interface:
Apply the ServiceContractAttribute with the service namespace.
Apply the XmlSerializerFormat(SupportsFaults = true) attribute.

On the interface's operation:
Apply FaultContractAttribute.
Apply OperationContractAttribute.

On the service class:
Apply any behaviour attributes, such as for error handling.
Apply the ServiceBehaviourAttribute, and set ConcurrencyMode = ConcurrencyMode.Multiple, IncludeExceptionDetailInFaults = false.

The operation should take a type such as:

[MessageContract(IsWrapped = false)]
public class Input
{
    [MessageHeader(Name = "headerData")]
    public Header Header { get; set; }

    [MessageBodyMember(Name = "inputData")]
    public Body Body { get; set; }
}

The response must be similar:

[MessageContract(IsWrapped = false)]
public class Response
{
    [MessageHeader(Name = "headerData")]
    public Header Header { get; set; }

    [MessageBodyMember(Name = "responseData")]
    public Body Body { get; set; }
}

0 comments:

Post a Comment