Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 9th, 2008, 07:54 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default Web Service, Custom Control, Custom Return Type

Hi All,

I have run in to a problem (which I have blogged here: http://tinyurl.com/6koh6b).

In short:

I have a web service which returns a custom type.
I want to be able to use this custom type as a property for a control.
When I query the service in a ASP.NET page, and try to set the property of the control, it comes back with a type mismatch because one is of type WebServiceName.CustomType, while the other is DLLName.CustomType. Is there any way to get around this other than hacking the proxy class?

Many thanks,

Rob
http://cantgrokwontgrok.blogspot.com
__________________
Rob
http://cantgrokwontgrok.blogspot.com
Reply With Quote
  #2 (permalink)  
Old June 9th, 2008, 01:03 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You'll need to do some kind of conversion between the custom web service type and the local type. This may be a good place to use the Adapter Pattern. As the HFDP book (which I know you have Rob!) says:

"The Adapter Pattern converts the interface of a class into another interface that clients expect..." [HFDP, 243]

So you need to build an adapter class that is composed of the web service type and implements the interface of the custom type. If your custom type is not already an interface then you may need to refactor it a bit.

- Head First Design Patterns (HFDP), O'Reilly Press (Sorry, Wrox)

-Peter
compiledthoughts.com
Reply With Quote
  #3 (permalink)  
Old June 10th, 2008, 02:36 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Peter!

Thanks very much for the response! I think you read my mind, this is exactly what I was thinking, but I thought I should ask around to see if there is a more "elegant" solution.. From the looks of it, I dont think there is, which kind of makes sense since when using a web service you are programming against the proxy, NOT the DLL/Whatever.

Will mean a bit of refactoring, but should still be pretty neat, and I am funny about "neat" code :D

Thanks again, and on a personal note, I hope all is well your end and everything is going swimmingly with your projects :)

Rob
http://cantgrokwontgrok.blogspot.com
Reply With Quote
  #4 (permalink)  
Old June 10th, 2008, 03:42 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

OK, I have made changes and still having problems! :(

I have now created an interface for each main component, and implemented the interface in each of the actual components.

The probem is exactly the same now, since I cannot set the return type of the web service to an interface, since they cannot be serialized. And when I try and perform a cast to cast it to the interface it comes back with this [new] error:
Code:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: Method Pages.GetList can not be reflected. ---> System.InvalidOperationException: There was an error reflecting 'GetListResult'. ---> System.NotSupportedException: Cannot serialize interface HTEC.Online.Presentation.Pages.ISerializableList.
How come this cannot be reflected? GetList is returning a SerializableList type, which works fine unless I try and cast it to the interface..

Do I need to add something to the interface?

Damn, I really thought it was going to work! :(

Rob
http://cantgrokwontgrok.blogspot.com
Reply With Quote
  #5 (permalink)  
Old June 10th, 2008, 05:35 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

OK, looks like I was completely going at this from the wrong angle!

I have now ditched the interfaces and simply created a method within the web app to convert to the appropriate type.
I did this because:

• The web reference will change in each subsequent web app, meaning the "type" will change.
• I didn't like having interfaces all those interfaces.
• It just made sense and made me feel stupid :D

Still have a few little bits to iron out, but I can actually get the return data from the web service now and pass it to the control.

It would be nice if I could create some sort of generic for this, but would need to utilise some grey matter for that :)

Rob
http://cantgrokwontgrok.blogspot.com
Reply With Quote
  #6 (permalink)  
Old June 10th, 2008, 07:47 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Rob,

Where were you making the first fix attempt? At the service end or the consumer end?

My apologies for not being more explicit. I was suggesting that you build the adapter on the consumer end since it's the web service return type (built automatically into the proxy) that you need to adapt to fit your control property.

-Peter
compiledthoughts.com
Reply With Quote
  #7 (permalink)  
Old June 10th, 2008, 08:03 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Peter,

TBH, its seems I have no idea what I was doing! I created an interface and then implemented the interface in the
Type within the DLL, thinking it would propagate through to the Web Service. I then updated the Control to accept
objects of the Interface type.

This of course never worked because Interfaces cannot be serialized, and it beared no relevance on the actual#
problem :)

No problem on not being more explicit, as soon as my brain kicked into gear I knew exactly what you were getting at!
Hell, the adapter pattern is one of my favourites! (making things appear to be ducks in HFDP I believe? :))

All is working fine now! Lesson learned? Wake up before trying to work! :D

Rob
http://cantgrokwontgrok.blogspot.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Server Control....Custom Property Editor ZArrinPour ASP.NET 1.0 and 1.1 Basics 1 June 15th, 2010 11:30 AM
Web Method Returning a complex Custom data type. saisunil1978 .NET Web Services 0 July 15th, 2008 05:38 AM
Web Service Custom Objects Problem Amateur .NET Web Services 0 March 19th, 2006 11:52 AM
Return a custom type from a web service gabrieldcr2 .NET Web Services 1 November 27th, 2005 01:26 PM
Web Custom Control prakashpatil_1978 ASP.NET 1.x and 2.0 Application Design 11 August 30th, 2004 07:35 AM



All times are GMT -4. The time now is 02:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.