How to use a custom object in a web service parameter
Posted on 2007-08-09
I have a visual studio solution with a web service project and a project that is a client for that service. There is a third project which is my Data Access Layer for this solution. In the DAL i have a custom struct that holds the info i want to send to my web service and a function that queries the database to create an array of these objects.
When i use the web service in the client i call the DAL function to get the array of objects i want to pass as parameters in my web service function call. It does not work to pass the objects as they are returned from the DAL function to the web service function (even though the web service is set up to take the same struct defined in the DAL). The web service function expects to see a type of MyWebservice.MyStruct and what is returned from the DAL function is DAL.MyStruct. These types do not implicitly cast to eachother (even though they hold the same data). So i have to create a new instance of MyWebservice.MyStruct and fill it with all the values in the DAL.MyStruct that is returned from DAL function.
The best solution would be one which allowed me to pass the value coming back from the DAL function to the web service function directly.