views:

35

answers:

1

I am relatively new to web services in .Net, so I apologize if this is a newbie sort of question.

I have found numerous resources on how to implement web services in a .Net project, but all of them seem to involve static definition of the exposed methods. While this may be suitable for some applications, it does not fit the bill for what I'm needing.

What I'm wondering is, is there a way to dynamically implement the methods exposed in a WSDL, such as the way the PHP SoapClient does it?

+1  A: 

The WSDL really is there just to help define the method names and params, and to mask all the HTTP headers for you, the developer.

Sounds like you're wanting to supply the method name and params at runtime. Perhaps a way around this is to completely forget about the WSDL altogether. Make your own HTTP calls.

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(
      "http://foo.com/Some.asmx"); //build string from .config instead.

//here Register is the name of the method. take yours from config as well if needed
req.Headers.Add("SOAPAction", "\"http://tempuri.org/Register\"");

req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";

See the article Invoking Web Service dynamically using HttpWebRequest for full details.

The thing about .NET's web service wrapper classes in general, is that they're trying to help enforce the server's contracts with the client. Obviously you're trying to avoid changing the statically typed clients, as presented by the .NET wrapper classes. Hopefully it won't be too onerous for you to maintain.

p.campbell
Thanks for the response but I'm not quite sure this is an adequate solution. That having been said, I'm going to have to rethink my client all together, because this seems to be consistent across the different message protocols I've thought about using.
Skudd
@Skudd: it'll be tough to get around. Having the contract changing is a bit of a tough road to travel. Boiling it down, you're dealing with method names in strings, and an undetermined number of params. This solution cuts out the WSDL and static typing, and allows you to react quickly to the changing web methods. Basically it's taking control of the HTTP call without rediscovering, recoding, recompiling, and redeploying. It'd definitely be more convenient for you if the server was stable, and/or used nice versioning methodologies.
p.campbell