Saturday, 10 May 2008

DDD Scotland: First Session

Web Services: We dont need no stinking web server

Barry Dorrans


  • What is WCF
  • WCF Vs Remoting
  • SOA, Services, Interfaces
  • Proving it

Remoting is going, WCF is an open standard (WS*) so much better, Also transport neutral so we can quickly switch from HTTP to TCP/MSMQ etc.

Roman Kiss has a null transport module which allows you to just communicate in memory

WCF Vs Remoting

  • WCF requires less permissions, runs in medium trust (mostly).
  • Easier versioning with WCF.
  • Two way communications (callback contracts)

SOA approach. Write the contracts first.

ABCs of WCF: Address (where to talk), Binding (how to talk), Contract (what we are talking about)

A server endpoint is constructed of Address binding Channel

A service can have multiple bindings - defines the shape of the service and the security.

A contract is defined for the service, data and message - can also create one for errors etc.


MEP: Message Exchange Protocol

  • Request - Reply
  • One Way
  • Duplex

Service Contracts are decorated with the attribute [Service Contract] and the methods with [Operation Contract]


Data contracts are decorated with [DataContract] and properties/functions with [MemberContract] - this gives us control of the message body or header - but ordering allows us to create optional components or to order them.


Step by Step instructions will be published


Create a WCF service library

Visual studio 2008 includes a test client for the library project. This even lets you inspect your request/response header.


Shows a simple?! wcf configuration file. Right clicking on it bring up the WCF configuration editor. This allows you to really easily change settings like the bindings.


WCF doesn't require a webserver to host HTTP web services

With windows 2008 it gets better. In XP/Vista we have to write a host if we dont use IIS with WAS we can host a service under any protocol underneath IIS.

Running through a demo called Rumour. Talks about using a constant file to define the namespace.

Name spaces should include a date to support versioning to prevent breaking changes

showed how you can set isrequired=false but did this on an int... not sure how WCF can handle a value non nullable type not being passed in?: Barry said that this would result in the int being set to a 0.

Barry recommends using Visual Studio 2008 because 2005 doesn't have a test harness.


What have we learned

We need data contracts for versioning. WCF will not send items down unless members are marked as a data contract. Barry claimed that even if you mark data as serializable it wont send it down the link... Im not sure this is correct as im sure I have done this... so I will chase it up


Showed the MEX endpoint exposing meta data information.

To stop the service you must do:-

internal static void StopService()


if(myServiceHost.Stae == CommuncationState.Faulted)


else if (myServiceHost.State!= CommincationState.Closed)



The reason we need this is because you cant use the using statement. Disposing of the WCF service calls close but if it is in a faulted state then it will throw an exception.


Do try and host WCF in IIS.


Replacing ASMX - double decorate contracts what the action & message names, rename the service and only use basic http binding.

Demonstrated creating a service host by passing in the base address

AddressAccessDeniedException - the process does not have rights to the name space, so that needs to be registered... however you can just run as admin.

This command allows you to register the address:

netsh http add urlacl url=http:\\+:8080\RumourService user=builtin\users

This should be done at install time.

Getting service host information:


Add service reference and discover is clever enough to check local projects (if they have an app.config file). Does this require the mex data?

The app.config then needed to be renamed to stop an error from happening

[My battery ran out even after a full charge - need a new one! so had to resort to manual blogging (pen&paper) - apologies if if this not as accurate]

Error Handling

Need to turn on error propagation on in the web.config. This then send the error message through but still sends it as a fault exception.

You can declare a data context which is decorated with the fault contract which allows the correct error to be send to the client and handled.

This then marshals everything into a soap fault


Barry then did a very quick run through of duplex working.

No comments: