views:

100

answers:

1

Hello All,

I am designing a framework for the use of error codes in an already very developed application.

There are several web services that handle database interaction and then there is the UI. If an error occurs in the web service the error code will need to be passed to the UI and processed (for showing user friendly error messages or something like that).

Now, the web service methods pass three kinds of objects: ints, strings, and data sets

For ints and strings it is easy to pass the error code (The int can be the actual code and the string can just add the code to the end of it in some way). However, it is not that simple with a dataset. Therefore, the idea was passed around to use a generic container and put the dataset and the error code in that.

Here is where the issue is:

When I created the generic container and attempted to use it I received the following error:

(Lets assume my generic class is called ErrorHandler<DatasetType>)

"Cannot convert ErrorHandlerofDatasetType to type ErrorHandler<DatasetType>"

Im assuming the WSDL is interpreting the class incorrectly or something. Can someone please shed some light on this?

EDIT: I should probably mention that this is for a .NET 2.0 solution.

+1  A: 

There is nothing wrong with your WSDL.

WSDL depends on XML Schema to describe the shape of data. XML Schema has no concept of generics.

When .NET sees your request to create a WSDL, and sees that you are using a generic type, it needs to generate a type name that it can use in the XML Schema. This is where "ErrorHandlerOfDatasetType" comes from.

When the client proxy code is being created, the XML schema in the WSDL is examined. The code generator will see a complexType named ErrorHandlerOfDatasetType, and will naturallly generate a class named ErrorHandlerOfDatasetType.

Now, you appear to be attempting to cast this proxy class to ErrorHandler, which it clearly is not. If you are using a "Web Reference" (you didn't say), then you should not have any server data types in your client. ASMX web services are not built that way.

If you are using WCF (and you should), then you can set the "Add Service Reference" dialog to share types between the client and the service. To be honest, I don't think that will help you with generics, because, as I said, the information necessary to know that ErrorHandlerOfDatasetType really means ErrorHandler is just not there.

Note that even in WCF, using a server type creates a dependency on the version of the server assembly, and is often not a good idea.

John Saunders