473,546 Members | 2,244 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InvalidCastExce ption 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
(WebServiceServ er.objectA) from the webservice to pocketPC.Object A (results
in InvalidCastExep tion). 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.Object A in
the PocketPC code I get the exception. I’ve also replaced the representation
of pocketPC.Object A in Reference.cs with a copy of the actual
pocketPC.Object A. 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 = sSomeStringDete rminedByWebServ iceBizLogic;
this.sStringB = sSomeStringDete rminedByWebServ iceBizLogic;;
this.sStringC = sSomeStringDete rminedByWebServ iceBizLogic;;
}
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 GetObjectAFromW ebService()
{
WebServiceServe r.Service ws = new WebServiceServe r.Service();
object tmpObject = (object)ws.GetO bjectAForPocket PC(someParamA,
someParamB);
ObjectA objectA = (ObjectA)tmpObj ect;
//The above cast results in the InvalidCastExce ption

//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.GetObjectAFo rPocketPC (someParamA, someParamB)
return objectA;
}

Sep 6 '06 #1
2 2784
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**@discussio ns.microsoft.co mwrote in message
news:70******** *************** ***********@mic rosoft.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
(WebServiceServ er.objectA) from the webservice to pocketPC.Object A
(results
in InvalidCastExep tion). 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.Object A
in
the PocketPC code I get the exception. I've also replaced the
representation
of pocketPC.Object A in Reference.cs with a copy of the actual
pocketPC.Object A. 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 = sSomeStringDete rminedByWebServ iceBizLogic;
this.sStringB = sSomeStringDete rminedByWebServ iceBizLogic;;
this.sStringC = sSomeStringDete rminedByWebServ iceBizLogic;;
}
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 GetObjectAFromW ebService()
{
WebServiceServe r.Service ws = new WebServiceServe r.Service();
object tmpObject = (object)ws.GetO bjectAForPocket PC(someParamA,
someParamB);
ObjectA objectA = (ObjectA)tmpObj ect;
//The above cast results in the InvalidCastExce ption

//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.GetObjectAFo rPocketPC (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.Obje ctA'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**@discussio ns.microsoft.co mwrote in message
news:70******** *************** ***********@mic rosoft.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
(WebServiceServ er.objectA) from the webservice to pocketPC.Object A
(results
in InvalidCastExep tion). 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.Object A
in
the PocketPC code I get the exception. I've also replaced the
representation
of pocketPC.Object A in Reference.cs with a copy of the actual
pocketPC.Object A. 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 = sSomeStringDete rminedByWebServ iceBizLogic;
this.sStringB = sSomeStringDete rminedByWebServ iceBizLogic;;
this.sStringC = sSomeStringDete rminedByWebServ iceBizLogic;;
}
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 GetObjectAFromW ebService()
{
WebServiceServe r.Service ws = new WebServiceServe r.Service();
object tmpObject = (object)ws.GetO bjectAForPocket PC(someParamA,
someParamB);
ObjectA objectA = (ObjectA)tmpObj ect;
//The above cast results in the InvalidCastExce ption

//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.GetObjectAFo rPocketPC (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
565
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 installed on Windows 2003 Server, the application works well, and the COM object can be called just as it's meant to be. The service is however running...
2
2388
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 cause this? I just want to be able to use my own node class so that I can store extra data... =========================
0
1854
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 type System.String. I am able to call other methods within the same web service but not this one. Here is the generated code for this method after...
1
18144
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 is serialized correctly, and the server returns a response (I've captured the response and it's correct!) but when the .NET deserialize this...
6
343
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 I’m unable to receive and a custom object. The error occurs when the PocketPC app casts a returned object (WebServiceServer.objectA) from the...
0
1204
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 browser when i invoke the service during test. Code: public class returnType { public _chassisdata chassisdata;
0
949
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 instance of the object on the calling asp page, but when i try to populate the properties, I get error: 438 - Object doesn't support this property or...
1
2379
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 string as the object and my own custom Structure as the type, T. Then I received an InvalidCastException. This is despite the fact that a CType from...
6
4965
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 has two columns, User and Tel number. User is filled with 1,2,3 and tel number has 3 telephone numbers. The User data column is specified as...
0
7507
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7698
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7794
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6030
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3472
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.