With .NET, consuming web services is a snap. Heck, it's not all that difficult without .NET, but it sure makes it even easier. In general, and for simple cases, all you need to do is add a web reference to the target .asmx, have the proxy generated (via VS.NET or wsdl.exe), and you're off to the races.
Some additional care and consideration should be taken, however, when the data returned from the web service can vary in format and structure. Allow me illustrate this with an example:
Suppose you are developing an application that must consume some data from a web service. This web service returns structured data that, via the auto-generated proxy, is represented in a class. For argument sake, this class is Customer (which derives from BusinessObj) and it has a few properties as identified below:
[XmlInclude(typeof(customer))]public abstract class BusinessObj { }[XmlType(Namespace="http://schemas.devstone.com/svc")]public abstract class customer : BusinessObj { public string id; public string name;}
Furthermore, this web service is part of a larger application that a company will purchase and deploy internally. In fact the customer may customize each type of data (e.g., Customer) by adding custom fields and attributes. Your component is designed as a 3rd-party add-in for this application and may be deployed across this varied environment.
Some customers will leave the base application alone (not customizing it) where other will 'go-to-town' and change the schema entirely to fit their business needs.
The question is this: how can your application operate in such a varied environment, consume the web service, and process all of the customizations that the customer has implemented?
You cannot, for instance simply create your web service proxy against the default schema and expect that to work. The reason being that once you deploy your component into a customized environment, your proxy will not know about the custom fields and cannot serialize/deserialize them. You won't get an error, per sé, but any custom fields will be ignored and not made available to your application.
This could be disastrous in the event that you needed to populate or read the custom fields.
How would you approach this problem?
NOTE: I'll post my answer tomorrow (or perhaps tonight) of how I've implemented it in the past to great success.
Remember Me
a@href@title, b, i, strike
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008R. Aaron Zupancic
E-mail