views:

31

answers:

3

I want to write a high level design document for a application which will expose it's webs ervices for various clients. For this purpose I need to provide the WSDL of webservices that we will develop in the future at server side. I've use web services earlier but never drill down in the details of WSDL.

I searched a lot and found that I need to generate WSDL using XML and XSD. Well, I yet to design both and I think this would be my first step.

Now my concern here is that it is very difficult to work with raw XML and I am not master in WSDL terminology.

Can anyone suggest what are the high level steps that one should perform to create a simple WSDL with some fault information in it?

Any insight would be helpful.

Thanks guys.

A: 

It is probably easier to just use WCF to create your WSDL for you. You just need to define your OperationContracts and DataContracts. You don't have to implement the operations just define what they are in an interface.

Vadim Rybak
A: 

Actually if you are following contract first development you should generate your "Messages" first .

In classic Web services you would actually start with XSDs for your requests, and responses. Then generate the code from the XSDs to guarantee that your data types are compliant with SOAP. Fortunately the DataContractSerializer has become very smart and will take care of your data types for you.

With that in mind, you should generate your Service Contract(s) and Request / Response messages (Data Contracts) first. When you expose a mex endpoint in WCF your WSDL will be generated for you. Creating your own WSDL can be very complex and really the only reason you should attempt it is if you actually want to hide functionality from certain consumers. Even if you wanted to generate your own WSDL for this reason, it would still be easier to let WCF create if for you and then alter it as you saw fit.

Let's stop here and see if you have any further questions.

CkH
A: 

My motivation for contract-first web services was to allow the service and the client to be written in parallel by different developers. Using WSDL and "Add Service Reference", you have to publish the service before you write the client.

As an alternative, don't go through WSDL. You can write one .NET interface that is shared by both the client and the service. This class will generate a WCF proxy directly from an interface:

public interface IServiceClientFactory<TServiceInterface>
{
    void CallService(Action<TServiceInterface> action);
    TResult CallService<TResult>(Func<TServiceInterface, TResult> function);
}

public class ServiceClientFactory<TServiceInterface> :
    IServiceClientFactory<TServiceInterface>
    where TServiceInterface : class
{
    class Client : System.ServiceModel.ClientBase<TServiceInterface>
    {
        public TServiceInterface Service
        {
            get { return base.Channel; }
        }
    }

    public void CallService(Action<TServiceInterface> action)
    {
        Client client = new Client();

        try
        {
            action(client.Service);
            client.Close();
        }
        catch (Exception)
        {
            client.Abort();
            throw;
        }
    }

    public TResult CallService<TResult>(Func<TServiceInterface, TResult> function)
    {
        Client client = new Client();

        try
        {
            TResult result = function(client.Service);
            client.Close();
            return result;
        }
        catch (Exception)
        {
            client.Abort();
            throw;
        }
    }
}

More details at Adventures in Software.

Michael L Perry