473,406 Members | 2,259 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,406 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 2758
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.