Non-standard types in data contracts

Topics: July and December Releases Forum
May 17, 2007 at 4:46 PM
Hi,
I am trying to create a DataContract that contains say a DataMember of type System.Drawing.Bitmap. I just can't seem to get this to work. First, I tried using the guidance recipe to create the member, but I could never get the validation in the wizard to let me through (I have added the System.Drawing.dll to the corresponding project). So I tried the next best thing which is to have a place holder like "System.Int32" and then go in and change the type manually in the contract. After exposing the service, I can't seem to add the service reference to the client project and I get the "Cannot import wsdl:port" error. Looking at it in more detail, I find the following problem:
Detail: An exception was thrown while running WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: ISerializable type with data contract name 'Bitmap' in namespace 'http://schemas.datacontract.org/2004/07/System.Drawing' cannot be imported. The data contract namespace cannot be customized for ISerializable types and the generated namespace 'xxx.xx.Service' does not match the required CLR namespace System.Drawing. Check if the required namespace has been mapped to a different data contract namespace and consider mapping it explicity using the namespaces collection.

I tried many other things like adding the System.Drawing reference to the web project -> it wasn't even possible to add this dll to the reference using the standard add reference dialogs. I am kind of stuck at the point and I notice that this problem only happens for custom types defined in other assemblies (be it dotnet assemblies from MS or my own assemblies). I would very much appreciate if someone could shed some light on what is going on.
Thanks,
Vasi
May 17, 2007 at 5:50 PM
Hi,
Some more information on the above problem. System.Drawing.Point and System.Drawing.Rectangle (i.e. value types) seem to work. The problem is with Bitmap and I suspect reference types in general.
Vasi
May 17, 2007 at 7:04 PM
The problem is now solved. I just had to use the powerful svcutil command line utility with a reference to System.Dawing.dll to get things done. The value types worked because the recipe just invoked the simplest form of svcutil and this generated client side code that redefined Point and Rectangle. Of couse, this choked for Bitmap. Here's hoping that the recipe for generating a service reference in the software factory would expose more of the functionality of svcutil in the future...
Until then, its command line for me.
Vasi