Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Wednesday, November 24, 2010

What exceptions can a WCF channel throw?

It seems that expected exceptions from a WCF channel include:

  • TimeoutException
  • CommunicationException - FaultException, FaultException, EndpointNotFoundException etc.

MSDN describes the exceptions that are caused by communication errors.

Also from MSDN:

When implementing custom channels and binding elements, it is strongly recommended that your components throw only System.TimeoutException or CommunicationException-derived objects. In the case where your components throw a recoverable exception that is specific to the component, wrap that exception inside a CommunicationException object.

MSDN also describes how to specify and handle faults in WCF contracts and services.

Monday, April 26, 2010

WCF Tools

WCF test client: WcfTestClient.exe.

Trace viewer: SvcTraceViewer.exe.

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; }
}

Monday, March 8, 2010

Reserving HTTP namespace for use by self-hosted WCF application

I ran into the following error while creating a WCF application that is not hosted in IIS:

HTTP could not register URL http://+:8080/Logging/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).

The solution on Vista is to reserve the namespace for the user that wants to bind to this URI, which must be done as an administrator:

netsh http add urlacl url={url} user={user\domain}

See MSDN for more detail, and don't forget that you will need to configure your firewall if you want this address to be externally visible.