Yossi Dahan [BizTalk]


Friday, June 09, 2006

Web services and generics

In my previous post I've talked about the somewhat pointless casting that usually occurs when you need to pass objects between your client and a web service.

The solution to this was to tweak the generated proxy class to use the shared definition of the classes rather then athe local, generated, definition of them.

Another requirement that sent us changing the proxy is the use of generics in our shared classes.

Generics have proven to be very convinient and useful to us and we use them quite frequently in our project.

However, when we started to expose web services that takes or returns our objects that use generics we've noticed that in all the generated proxies the generic memebrs have been converted to arrays.

For instance - a member defined as List(Of String) (we're using VB.net) has been changed to be an array of strings.

This meant that we cannot use the code we already have to use these objects as it assumes the members are defined as lists and not arrays.

the solution is to modify the generated proxy to use the generics form. (in our case, since we removed the local definition of the class anyway as described in my previous post, we "killed two birds with one stone" as the original class definition, now used by the proxy, uses the list types)

While you do have to be a bit careful with this approach when exposing such services to external paries, as you can't assume they can use generics, it's definitely useful for internal service.

Howerver, a lesson we learnt while hooking all of this to BizTalk (which needs to expose services that take these objects) is that on the wire, List (Of T) and Arrays look the same. which means they are quite interopable (and that you can use this form of generics with BizTalk as well)


Post a Comment

<< Home