Search code examples
c#asp.netweb-serviceswsdl

How to override Wsdl generation in Web Services .Net


I would like to create a WebService in .Net who expose multiple WebMethods

I need a WebService version per new implementation (WebMethod or New Property in Business Object), like this :

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
    [WebMethod]
    [WebServiceVersion("1.0")]
    public string HelloWorld()
    {
        return "Hello World";
    }

    [WebMethod]
    [WebServiceVersion("1.1")]
    public string NewMethodInVersion1_1()
    {
        return "Hello World";
    }
}

With UrlRewriting or HttpHandler :

HelloWorld WebMethod only : http://localhost/Service/1.0/Service.asmx

HelloWorld WebMethod and NewMethodInVersion1_1 : http://localhost/Service/1.1/Service.asmx

How can i generate a wsdl dynamically for the specific version used by the customer ?


Solution

  • The solution :

    1. Create one directory per web service version : /1/; /2/; /3/ ...
    2. Each version of web service inherit from the previous version : /2/Service : _1.Service; /3/Service : _2.Service ...
    3. Implement the XmlSchemaProvider on the object directly return by your WebMethod with a custom serialization using IXmlSerializable interface
    4. Expose properties using a WebServiceVersionAttribute (ex : The property Account is only exposed for web service version greater or equal of 2)
    5. Use a HttpModule to intercept the web service version (with a regex : new Regex("/([0-9])+/(.)*"))
    6. WriteXml method of IXmlSerializable interface checkes WebServiceVersionAttribute to filter the Xml result (in order to not serialize properties of a greater version)

    The biggest difficulty is to implement the XmlSchemaProvider ...