Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 23rd, 2005, 11:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default Custom classes in Web Services

Hi I am creating a Pocket PC application that I want to exchange data via web services.
I have created a class library of the classes I wish to pass to anf from the client.
I have referenced that in both the client project and the web service project.
The problem is that now when I try to call a web service using a parameter of a custom class the web service does not see them as the same thing.

How do I pass custom classes from the client to the web service?

Many thanks for your assistance

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
__________________
======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
 
Old November 24th, 2005, 10:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Im desperate!
Thanks to all those that have taken the time to look at my problem.
As no one has come forth with a suggestion I would like to offer more info in the hope that someone can assist.
Please find extracts of the code to illustrate the problem below.
It appears that the web service is changing the namespace of the object I wish to use.
How do I go about passing such information?

*** WEB SERVICE EXTRACTS ***
I have added a reference to the project MPAClassLAyer which holds the class definitions I wish to transport over soap.
The example method takes parameters of a Driver and a MPAData data structure both of which are defined in the class layer.

using MPAClassLayer;

    [WebMethod()]
    public MPAData Syncronize(Driver driver, MPAData mpaDeviceData)
    {


*** APP Exctracts ***
I have added the same class layer reference to the project file(MPAClassLayer) hoping to have the same classes available at both ends
       public static bool Syncronize(Driver driver)
        {
            //Get the current dataset from the pda
            MPAData mpaDeviceData = GetPdaDriverData(driver.DriverID);

            //send to Web Sercive
            MPAWebServices.MPAService ws = new MobilePickupsAssistant.MPAWebServices.MPAService() ;
            MPAData mpaServerData = ws.Syncronize(driver,mpaDeviceData);
            ws.Dispose();


*** MPAData Class
This is the class I wish to pass

namespace MPAClassLayer
{
    public class MPAData
    {
        private MPAJobs jobs;
        private string driverID;

        public MPAJobs Jobs { get { return jobs; } set { jobs = value; } }
        public string DriverID { get { return driverID; } set { driverID = value; } }

        public MPAData()
        {
        }
        public MPAData(Driver driver)
        {
            this.driverID = driver.DriverID;
        }
        public MPAData(Driver driver, MPAJobs jobs)
        {
            this.driverID = driver.DriverID;
            this.jobs = jobs;
        }
    }
}

*** PROBLEM ***
I am getting the following error

cannot convert from 'MPAClassLayer.MPAData' to 'MobilePickupsAssistant.MPAWebServices.MPAData'
The same applies for Driver object

It appears that the web service is changing the namespace of the object I wish to use.
How do I go about passing such information?

Many thanks for your help

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old November 25th, 2005, 03:07 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I had this before, and my solution was to include the full namespace of the web service object (or through a using statement of course).

Something like:

com.YourDomain.YourService.YourObject myObject = myWebService.GetObject();

That references the external object you get from the web service.

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 25th, 2005, 06:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Hi Imar,
The problem is more related to the parameters that the web service is expecting.
The parameters are from the custom class which is imported into both the web service project and the device project.
But the Web service project expects parameters from its own namespace (This should be the same object as in the device project).
And the ones I have to provide it are from the custom class namespace.
I need to be able to identify them as the same thing.

Thanks again for your assistance.


======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old November 25th, 2005, 08:02 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I read an article in the MSDN magazine a while ago that had a solution for this problem. I believe this is the one: http://msdn.microsoft.com/msdnmag/is...L/default.aspx

although I haven't had the time to reread / check it.

A Google search term for your situation might be "type sharing" in combination with web services of course.

Hope this helps a little,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 25th, 2005, 09:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Thanks Imar,
I will look in to the document and investigate further.
There must be something I am doing wrong as I feel this should be a basic web service method.
How does anyone consume a web service with a custom class as a parameter?
I will go through some tutorials and see if the same problem arrises.
Many thanks again,
Rod

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old November 25th, 2005, 11:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Well, if you have already included the class library in your webservice project, and if your web service is making use of any of the classes defined in your class library, the WSDL for your webservice would include a SOAP compatible definition of that class in it. Just check the WSDL for the webservice you have created.
Test the webservice to see that it is running fine with its wsdl having the definition of the relevent custom classes.

Now if the WSDL HAS the custom class definition, you dont have to include the class library reference to your App, you can use the definition from you webservice reference only like this


            MobilePickupsAssistant.MPAWebServices.MPAData mpaDeviceData = GetPdaDriverData(driver.DriverID);

            MPAWebServices.MPAService ws = new MobilePickupsAssistant.MPAWebServices.MPAService() ;
            MobilePickupsAssistant.MPAWebServices.MPAData mpaServerData = ws.Syncronize(driver,mpaDeviceData);
            ws.Dispose();


U run into such problems 'cause of the difference between the ways .NET Framework and Compact Framework handle things, but if the WSDL has the definition of the relevent classes none would mind.

Regards
Ankur Verma
 
Old November 25th, 2005, 01:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Imar,
You are a legend.
Its seems so simple now, I dont need to reference the class library at all because it is duplicated in the web service.
I was using the class library for other things that will not be used in the web service or interface. But I guess if I keep the interface abstracted from the application, I can still ue the referenced library in the app for local processes like saving to the local SQL CE.
I will look into more and try what you have suggested.
Thanks again Imar, you are allways very generous with your knowledge.
Rod



======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
 
Old November 25th, 2005, 06:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Rod,

Glad I could help, and hope is all working now.

For the history of this thread, how did you fix it? Did you use the fully qualified namespace of the types?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: The man with the red face by Laurent Garnier (Track 7 from the album: Unreasonable Behaviour) What's This?
 
Old November 26th, 2005, 05:21 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Hi Imar,
I haven't actually fixed it as yet, but I intend to use the web service classes in the interface alone and not try to use the same class base for the web service and app.
Thanks again,
Rod

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Service, Custom Control, Custom Return Type robzyc ASP.NET 2.0 Basics 6 June 10th, 2008 08:03 AM
Send custom E-mail using sharepoint services ddaz0102 SharePoint Development 0 May 10th, 2007 01:42 PM
Custom Classes and Functions harpua Flash (all versions) 0 February 3rd, 2006 02:43 AM
Web Services Error (Ch18) - No Web Disc. Info. ElPato BOOK: Beginning ASP.NET 1.0 2 April 13th, 2005 03:27 PM
Custom Classes!! NitinJoshi General .NET 1 January 25th, 2005 01:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.