?
Solved

How to use a custom object in a web service parameter

Posted on 2007-08-09
3
Medium Priority
?
965 Views
Last Modified: 2013-11-07
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.
My Problem:
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.
0
Comment
Question by:dave4dl
  • 2
3 Comments
 
LVL 1

Expert Comment

by:LordHaze
ID: 19665551
Use Casting like so.
{
//Cast your class into an object and pass to foo
myWebService.foo((object)TestClassToBeSent);
//Webmethod target
[WebMethod]
public void foo(object SentTestClass)
{
   TestClass TestClass1 = (TestClass)SentTestClass;
   //TestClass1 now contains the object you passed.
}
}
0
 
LVL 15

Author Comment

by:dave4dl
ID: 19688226
Thanks for the idea lordHaze.

When i did what you said it gave me the following error:

NUnit_Tests.clsUnitTests.myTest: System.InvalidOperationException : There was an error generating the XML document.
  ----> System.InvalidOperationException : The type Web_Service_DAL.clsTableRecord[] may not be used in this context.

I am trying to pass an array of custom objects to the web service like:
objWebService.insertIntoTable((object)testRecords, "MyTable");

I defined the custom classes (the clsTableRecord contains, among other things, a custom object) as [Serializable]

Any light you can shed on how to do what i am trying to do would be much appreciated
0
 
LVL 1

Accepted Solution

by:
LordHaze earned 1000 total points
ID: 19689044
Try converting  to an ArrayList before passing, could have something to do with the Serializable Object.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question