Exercise: WCF web services, what is possible?

In this exercise you must find the limitations of WCF web services: What is possible, and what is not possible?

Getting started

  1. Project A: Make a WCF Service Application (the web service provider)
    Can be Azure or local.
  2. Project B: Make an ordinary Console Application (the web service consumer)
    Or use the WcfTestClient
  3. Find the URL of the WSDL file in the service provider
  4. Add a "Service Reference" to the web service consumer (use the URL of the WSDL file)

The development cycle

  1. Add a new method to the WCF Service
    Add to the interface + the implementation
  2. Run the service locally (Azure emulator)
  3. Update Service Reference in the consumer applicaton
  4. Add to the consumer/client application: Call the new metod
  5. Run the consumer/client application

Simple method

Make a simple method int Add(int a, int b) to add the number a + b

Exceptions

Add another method Divide(int a, int b).
What happens if b=0?

Add another method

This method must throw an exception if the number is 0, otherwise it returns the number as it is.

Overloading method names

Make another method double Add(double a, double b)

That is, another method with the same name as a the previous method.

Static methods

Is is possible to use static methods with web services?

Parameters: ref + out

In C# you can mark method parameters ref or out.

Is that possible in web services? How does it work?

When is it "interesting" to use ref or out parameters to web service methods?

Properties

Can you make properties (C# syntax) in SOAP services (in the interface that defines the service)?

Collections

Make methods to check which collections are allowed SOAP methods as parameters and return types:

Sync vs. async methods

All methods come in an ordinary version + an async version.

Try both of them.

What is the difference?

Composite types

Make a composite type: Class Student with a few properties + methods

Use the composite type as a parameter + return type in another WCF method.

Any requirements on the composite type: Public set on properties, parameter less constructor, etc.?

Collections + composite types

Composite type with a collection: Student with a collection of phone numbers

Collection of composite type objects.

State on the server

Add two method to the service provider:

How does it work?

Will the keyword static on the field, help you?