views:

61

answers:

3

Hi,

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 ?

A: 

If you were to do this would you not publish two seperate web applications/web site?

It would be safer than having two customers pointing at one web service, and have the risk of them calling the wrong method.

You would then just point at the relevant web application/web site and get the WSDL.

Datoon
If a bug occur in the version 1.0, i need to release the fix without deploy the new webmethod or property of the newer versionAnd i don't want to branch in VSS or TFS the multiple version of my WebService
Jni
Wouldn't you have to release anyhow because you have to fix the code behind version 1.0. My method would allow you to release just 1.0 version of the code and not affect version 1.1 of the web service?
Datoon
I can't use 2 WebApplication because new property of the business object will be added in the future, so i need to separate wsdl modification in each version.In a old project, i deploy on the server each version in a separator WebApplication on IIS. But when a bug occur, it was very hard to fix in each web application version
Jni
Can you be a bit clearer in what you are trying to achieve?Is it correct you have your business objects as part of your web service tier?
Datoon
A: 

I temporary solved my problem by serve another wsdl file with a HttpModule

public class WsdlModule : IHttpModule
{
    public void Dispose()
    {
        throw new NotImplementedException();
    }

    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(context_BeginRequest);
    }

    void context_BeginRequest(object sender, EventArgs e)
    {
        HttpApplication app = sender as HttpApplication;
        HttpContext context = app.Context;
        HttpRequest request = context.Request;
        HttpResponse response = context.Response;

        string url = request.Url.AbsoluteUri.ToLower();

        if (url.Contains("wsdl"))
        {
            response.WriteFile(context.Server.MapPath("wsdl/1.0/Service.wsdl"));
            response.End();
        }
    }
}

if possible, i prefer to dynamically generate the wsdl file

Jni
A: 

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 ...

Jni