views:

1266

answers:

7

Hello again ladies and gents!

OK, following on from my other question on ASP.NET Web Service Results, Proxy Classes and Type Conversion. I've come to a part in my project where I need to get my thinking cap on.

Basically, we have a large, complex custom object that needs to be returned from a Web Service and consumed in the client application.

Now, based on the previous discussion, we know this is going to then take the form of the proxy class(es) as the return type. To overcome this, we need to basically copy the properties from one to the other.

In this case, that is something that I would really, really, really! like to avoid!

So, it got me thinking, how else could we do this?

My current thoughts are to enable the object for complete serialization to XML and then return the XML as a string from the Web Service. We then de-serialize at the client. This will mean a fair bit of attribute decorating, but at least the code at both endpoints will be light, namely by just using the .NET XML Serializer.

What are your thoughts on this?

+1  A: 

I had some great answers on a very similar topic yesterday that might be useful for you:

Communication between javascript and the server

mercutio
+2  A: 

The .Net XML (de)serialisation is pretty nicely implemented. At first thought, I don't think this is a bad idea at all.

If the two applications import the same C# class(es) definition(s), then this is a relatively nice way of getting copy-constructor behaviour for free. If the class structure changes, then everything will work when both sides get the new class definition, without needing to make any additional changes on the web-service consumption/construction side.

There's a slight overhead in marshalling and demarshalling the XML, but that is probably dwarved by the overhead of the remote web service call. .Net XML serialisation is well understood by most programmers and should produce an easy to maintain solution.

Cheekysoft
+3  A: 

Im loving JSON for this kind of thing. I just finished a POC drop-things type portal for my company using jquery to contact web services with script service enabled. The messages are lightweight and parsing etc is pretty much handled. The jquery ajax stuff i read was here (loving it!) : jquery article

Peter Short
A: 

Thanks for the suggestions guys. Sadly I don't think JSON is an option since the boss has made it clear we would like to keep things as "standard" as possible (too many previous probs with lots of "odd" bits).

+1 for the JSON recommendations though since they would be great for this scenario if otherwise! :)

Rob Cooper
A: 

Rob, in looking at your other question as well as this one, it's sounds like the exact situation we have in our environment. What we've done, however, is move away from ASP.Net web services to WCF web services and in the process solved (for the most part) this problem.

If there is any chance your web service could be implemented as a WCF web service, this might work for you as well. I should mention, that at the same time, we've maintained backwards compatibility with some client applications that need the "ASP.Net web service style" of implementation by using the WCF basichttp binding for the service transport. The end result is that our "newer" client applications are able to use our real business objects (through referencing an assembly containing only these shared objects) as the return types from the web service calls because they make actual WCF calls.

We do this by not utilizing the auto-generated proxy classes and constructing our own client channel to communicate with the WCF service.

If you can possibly use WCF, let me know I can post some additional information.

Peter Meyer
A: 

Hi Peter, thanks for your response. Sadly, upgrading to .NET 3.x isn't really an option yet.. The truth is, the company I am in were hesitant about moving to 2 (I think perhaps through lack of understanding and timescale requirements).

And to be perfectly honest, as you can tell, I'm pretty new to ASP.NET myself! I think I will skip the WCF part for now, but rest assured, when it comes around I will be right back with WCF-related questions! :D

Thanks again.

Rob Cooper
A: 

Rob, you're welcome and good luck. I've been in a similar situation in the past and know all too well working within such constraints!

Peter Meyer