Creating WSDL from nothing

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

In one SOA project, we have requirement to create the WSDL (Service Description) long before the service is deployed at all. Without of explaining why we need that, imagine that you have all required to deploy the service. That means you know the contract to be used, the binding, required security and listening address. This is more or less all you need if you don't use custom policies.
Following code creates the WSDL for contract some ITestInterface and service listening at http://localhost/myservice with certificate based message security

public static void GenerateWsdlFromNothing()
{
  StringBuilder sb = new StringBuilder();
  BasicHttpBinding binding = new BasicHttpBinding();
  binding.Security.Mode = BasicHttpSecurityMode.Message;
  binding.Security.Message.ClientCredentialType =
  BasicHttpMessageCredentialType.Certificate;

  using(XmlWriter writer = XmlWriter.Create("my.wsdl"))
  {
    CreateWsdl(typeof(ITestInterface).AssemblyQualifiedName, 
    new EndpointAddress("http://localhost/myservice"), binding,
    writer);
 }
}

 


This code should give you an idea of requirement at all. As you see we do not use here Metadata Exchange to retrieve the service description. This is not possible, because the service do not exist at this point of time. All we have are peaces if information like binding and contract. The real work is behind method CreateWsdl. Next code snippet shows the implementation of this method:

public static void CreateWsdl(string contractQualifiedName,
  EndpointAddress address,
  Binding binding,
  XmlWriter writer)
{
  WsdlExporter exporter = new WsdlExporter();

  ServiceEndpoint[] myServiceEndpoints = new ServiceEndpoint[2];
  ContractDescription contractDesc = 
  ExportServiceContract(null, contractQualifiedName);

  ServiceEndpoint endpoint =
  new ServiceEndpoint(contractDesc, binding, address);

  exporter.ExportEndpoint(endpoint);

  MetadataSet metadataDocs = null;
  if (exporter.Errors.Count == 0)
  {
     metadataDocs = exporter.GetGeneratedMetadata();
  }

  metadataDocs.WriteTo(writer);
}


In this example we create the instance of WsdlExporter, which does the difficult job. To make it working we need to create the endpoint from service description, address and binding. Unfortunately, creating of service description is very tricky and it is described here.


Posted Jan 03 2008, 11:43 PM by Damir Dobric
Filed under:
developers.de is a .Net Community Blog powered by daenet GmbH.