473,230 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

InvalidCastException when casting object returned from web service

I have a .net framework 2.0 client (Pocket PC) and a .net 2.0 webservice that
communicate on the same LAN. The Pocket PC has no problem consuming strings
returned from the web service methoeds but I’m unable to receive and a custom
object. The error occurs when the PocketPC app casts a returned object
(WebServiceServer.objectA) from the webservice to pocketPC.ObjectA (results
in InvalidCastExeption). ObjectA is a simple class and is identical on the
PocketPC and Webservice. I’ve verified the object is being returned to the
PocketPC intact (debugging indicates all correct types exist and values
populated) but when I try to cast it from type Object to pocketPC.ObjectA in
the PocketPC code I get the exception. I’ve also replaced the representation
of pocketPC.ObjectA in Reference.cs with a copy of the actual
pocketPC.ObjectA. What am I doing wrong? Is this not supported by compact
framework?
Thanks,
Jim

public class ObjectA //same on client and web service
{
private string sStringA = string.Empty;
private string sStringB = string.Empty;
private string sStringC = string.Empty;

public ObjectA() { }

public ObjectA() string sParamA, DateTime dtParamB,string sParamC)
{
this.sStringA = sSomeStringDeterminedByWebServiceBizLogic;
this.sStringB = sSomeStringDeterminedByWebServiceBizLogic;;
this.sStringC = sSomeStringDeterminedByWebServiceBizLogic;;
}
public string StringA
{
get { return this.sStringA;}
set { this.sStringA = value; }
}

public string StringB
{
get { return this.sStringB; }
}
public string SringC
{
get { return this.sStringC; }
set { this.sStringC = value; }
}
}

Client code (Pocket PC)

public static ObjectA GetObjectAFromWebService()
{
WebServiceServer.Service ws = new WebServiceServer.Service();
object tmpObject = (object)ws.GetObjectAForPocketPC(someParamA,
someParamB);
ObjectA objectA = (ObjectA)tmpObject;
//The above cast results in the InvalidCastException

//I’ve also tried to assign directly to the PocketPC ObjectA but receive a
compile time error. The below statement does not work.
// ObjectA objectA = ws.GetObjectAForPocketPC (someParamA, someParamB)
return objectA;
}

Sep 6 '06 #1
2 2752
The returned object is of the type that it was when the Web Service
generated it, not an identical but different class which you copied.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

It takes a tough man to make a tender chicken salad.
"Jim S" <Ji**@discussions.microsoft.comwrote in message
news:70**********************************@microsof t.com...
>I have a .net framework 2.0 client (Pocket PC) and a .net 2.0 webservice
that
communicate on the same LAN. The Pocket PC has no problem consuming
strings
returned from the web service methoeds but I'm unable to receive and a
custom
object. The error occurs when the PocketPC app casts a returned object
(WebServiceServer.objectA) from the webservice to pocketPC.ObjectA
(results
in InvalidCastExeption). ObjectA is a simple class and is identical on
the
PocketPC and Webservice. I've verified the object is being returned to
the
PocketPC intact (debugging indicates all correct types exist and values
populated) but when I try to cast it from type Object to pocketPC.ObjectA
in
the PocketPC code I get the exception. I've also replaced the
representation
of pocketPC.ObjectA in Reference.cs with a copy of the actual
pocketPC.ObjectA. What am I doing wrong? Is this not supported by
compact
framework?
Thanks,
Jim

public class ObjectA //same on client and web service
{
private string sStringA = string.Empty;
private string sStringB = string.Empty;
private string sStringC = string.Empty;

public ObjectA() { }

public ObjectA() string sParamA, DateTime dtParamB,string sParamC)
{
this.sStringA = sSomeStringDeterminedByWebServiceBizLogic;
this.sStringB = sSomeStringDeterminedByWebServiceBizLogic;;
this.sStringC = sSomeStringDeterminedByWebServiceBizLogic;;
}
public string StringA
{
get { return this.sStringA;}
set { this.sStringA = value; }
}

public string StringB
{
get { return this.sStringB; }
}
public string SringC
{
get { return this.sStringC; }
set { this.sStringC = value; }
}
}

Client code (Pocket PC)

public static ObjectA GetObjectAFromWebService()
{
WebServiceServer.Service ws = new WebServiceServer.Service();
object tmpObject = (object)ws.GetObjectAForPocketPC(someParamA,
someParamB);
ObjectA objectA = (ObjectA)tmpObject;
//The above cast results in the InvalidCastException

//I've also tried to assign directly to the PocketPC ObjectA but receive a
compile time error. The below statement does not work.
// ObjectA objectA = ws.GetObjectAForPocketPC (someParamA, someParamB)
return objectA;
}

Sep 6 '06 #2
ok, how should I cast it to the client.ObjectA? Do I need to enumerate
through webservice.ObjectA's types and copy them each to client.ObjectA? I
hope not.
Thanks,
Jim

"Kevin Spencer" wrote:
The returned object is of the type that it was when the Web Service
generated it, not an identical but different class which you copied.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

It takes a tough man to make a tender chicken salad.
"Jim S" <Ji**@discussions.microsoft.comwrote in message
news:70**********************************@microsof t.com...
I have a .net framework 2.0 client (Pocket PC) and a .net 2.0 webservice
that
communicate on the same LAN. The Pocket PC has no problem consuming
strings
returned from the web service methoeds but I'm unable to receive and a
custom
object. The error occurs when the PocketPC app casts a returned object
(WebServiceServer.objectA) from the webservice to pocketPC.ObjectA
(results
in InvalidCastExeption). ObjectA is a simple class and is identical on
the
PocketPC and Webservice. I've verified the object is being returned to
the
PocketPC intact (debugging indicates all correct types exist and values
populated) but when I try to cast it from type Object to pocketPC.ObjectA
in
the PocketPC code I get the exception. I've also replaced the
representation
of pocketPC.ObjectA in Reference.cs with a copy of the actual
pocketPC.ObjectA. What am I doing wrong? Is this not supported by
compact
framework?
Thanks,
Jim

public class ObjectA //same on client and web service
{
private string sStringA = string.Empty;
private string sStringB = string.Empty;
private string sStringC = string.Empty;

public ObjectA() { }

public ObjectA() string sParamA, DateTime dtParamB,string sParamC)
{
this.sStringA = sSomeStringDeterminedByWebServiceBizLogic;
this.sStringB = sSomeStringDeterminedByWebServiceBizLogic;;
this.sStringC = sSomeStringDeterminedByWebServiceBizLogic;;
}
public string StringA
{
get { return this.sStringA;}
set { this.sStringA = value; }
}

public string StringB
{
get { return this.sStringB; }
}
public string SringC
{
get { return this.sStringC; }
set { this.sStringC = value; }
}
}

Client code (Pocket PC)

public static ObjectA GetObjectAFromWebService()
{
WebServiceServer.Service ws = new WebServiceServer.Service();
object tmpObject = (object)ws.GetObjectAForPocketPC(someParamA,
someParamB);
ObjectA objectA = (ObjectA)tmpObject;
//The above cast results in the InvalidCastException

//I've also tried to assign directly to the PocketPC ObjectA but receive a
compile time error. The below statement does not work.
// ObjectA objectA = ws.GetObjectAForPocketPC (someParamA, someParamB)
return objectA;
}


Sep 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Martijn Remmen | last post by:
I have developed a service which exposes a COM object. This service is running perfect on Windows 2000 Server and Windows 2000 Professional under the SYSTEM account. When the service is...
2
by: Benny Raymond | last post by:
More problems with this... When I run this code, the main form returns an invalid cast exception as it's executing the line "TreeNode n = (TreeNode) this.Nodes;" Does anyone know what would...
0
by: JGKjr | last post by:
I have a Web Application written in C#. I am trying to call a web service method and recieve the error: System.InvalidCastException: Cannot assign object of type System.Boolean to an object of...
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it...
6
by: Jim S | last post by:
I have a .net framework 2.0 client (Pocket PC) and a .net 2.0 webservice that communicate on the same LAN. The Pocket PC has no problem consuming strings returned from the web service methoeds but...
0
by: SaharImtiaz | last post by:
Hi there, I m trying to return an object (of my own written class) from a web service that contains jagged Arrays as public variables. Asp.Net is showing me the its serialized version on the...
0
by: joshua.oconnor | last post by:
I am having a problem accessing the properties of a structure object returned from a webservice. The web service returns an object: changeobject.description changeobject.user I can create an...
1
by: =?Utf-8?B?QkpT?= | last post by:
I have written a Generic method that takes an object, a type, T, and returns a System.Nullable (Of T) depending on whether or not the object IsDBNull. It was working fine until I tried to pass a...
6
by: dgleeson3 | last post by:
Hello All I have VB code (.Net 2005) reading from an SQL server 2005 database. Im getting InvalidCastException when doing reader.GetInt32(0) Im simply reading an int from a simple database. It...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.