.NET Web Serivce hydrate custom class
- by row1
I am consuming an external C# Web Service method which returns a simple calculation result object like this:
[Serializable]
public class CalculationResult
{
public string Name { get; set; }
public string Unit { get; set; }
public decimal? Value { get; set; }
}
When I add a Web Reference to this service in my ASP .NET project Visual Studio is kind enough to generate a matching class so I can easily consume and work with it.
I am using Castle Windsor and I may want to plug in other method of getting a calculation result object, so I want a common class CalculationResult (or ICalculationResult) in my solution which all my objects can work with, this will always match the object returned from the external Web Service 1:1.
Is there anyway I can tell my Web Service client to hydrate a particular class instead of its generated one? I would rather not do it manually:
foreach(var fromService in calcuationResultsFromService)
{
ICalculationResult calculationResult = new CalculationResult()
{
Name = fromService.Name
};
yield return calculationResult;
}
Edit: I am happy to use a Service Reference type instead of the older Web Reference.