OK - I have a possible solution for you that is not award-winning for elegance but I've just tested it and it works.
You can expose one WebMethod that returns object and takes a params object[] parameter, allowing you to pass whatever you like to it (or nothing) and return whatever you want. This compiles to legal WSDL using the 'anyType' type.
If you can identify which actual method to call based on the number and datatype of parameters passed to this method, you can call the appropriate method and return whatever value you want.
The service: -
[WebMethod]
public object Method(params object[] parameters)
{
object returnValue = null;
if (parameters != null && parameters.Length != 0)
{
if (parameters[0].GetType() == typeof(string) && parameters[1].GetType() == typeof(int))
{
return new ServiceImplementation().StringIntMethod(parameters[0].ToString(), Convert.ToInt32(parameters[1]));
}
else if (parameters[0].GetType() == typeof(string) && parameters[1].GetType() == typeof(string))
{
return new ServiceImplementation2().StringStringMethod(parameters[0].ToString(), parameters[1].ToString());
}
}
return returnValue;
}
My test service implementation classes: -
public class ServiceImplementation
{
public string StringIntMethod(string someString, int someInt)
{
return "StringIntMethod called";
}
}
public class ServiceImplementation2
{
public float StringStringMethod(string someString, string someOtherString)
{
return 3.14159265F;
}
}
An example of use: -
var service = new MyTestThing.MyService.WebService1();
object test1 = service.Method(new object[] { "hello", 3 });
Console.WriteLine(test1.ToString());
object test2 = service.Method(new object[] { "hello", "there" });
Console.WriteLine(test2.ToString());
I've tested this and it works. If you're interested, the WSDL that "Method" generates: -
POST /test/WebService1.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Method"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Method xmlns="http://tempuri.org/">
<parameters>
<anyType />
<anyType />
</parameters>
</Method>
</soap:Body>
</soap:Envelope>
Incase you're wondering, yes I am bored at work and I'm in the mood for helping people :)