views:

407

answers:

1

Hi, I'm new here and I hope anyonte can help me.

I have WCF Service and Windows Forms working with this client written in VB.NET. The Service class started to return xml serialized objects, but all my classes on Service side are DataContract-s and the service class is DataContractFormat. I googled everywhere about serializations and I couldn't find reason why it started to do that.

I checked my classes and service, app.config file, but I couldn't find anything.

I checked Reference.vb class, and it's System.Xml.Serialization.XmlElementAttribute everywhere. The question may seem dummy, but I really don't know what to do. I just want to know what can cause the service to act like that.

Thank you.

+1  A: 

So I assume you didn't knowingly change to using the XmlSerializer then, did you?

There are a number of circumstances when the WCF runtime decides to use the XmlSerializer instead of the DataContractSerializer, but typically, that's when you have an existing WSDL/XSD that contain certain elements that the DataContractSerializer can't deal with.

Did you check your Reference.vb class - often, the Add Service Reference function in Visual Studio will add comments into the generated file to explain why it switched to the XML serializer. Does it say anything at all??

marc_s
marc_s,No, I don't use XmlSerializer in my project.By "existing WSDL/XSD" you mean my own WSDL/XSD files or generated by wsf? I don't have neither WSDL, nor XSD files.I checked Refernce.vb and I found the same comment above most of service functions. It says:"'CODEGEN: Parameter '<function_name>' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlArrayAttribute'."Thank you for your response. I'll try to google the problem. Can this comment be the reason of my problem?What does it means
hgulyan
I can see generated code, xsd and wsdl files now,but it steel doesn't work.I added a function to service which returns array of my custom classesand after update of service reference, it generated xml serializedobjects.
hgulyan
it would appear by adding that array, you triggered WCF into switching to XML serializer mode. Is the object type you return in the array marked as [DataContract]? Can you try returning a List<YourObject> instead??
marc_s
Yes, I use DataContract mark in my custom classes and datamember mark on my properties. I changed my object arrays and custom class's arrays to list(of <MyObject>) and List(Of Object), but on the client side it doesn't chang return types to list, it's steel object arrays. Is it supposed to be so?In some cases I need to send a list of <id, description> pair, so I was sending object(), where every element is also an Object array with two values. Can that be the reason of my problem? If so, I wonder why it was working fine till now.
hgulyan
I forgot to mension that I changed the collection type to List in service reference's configuration, so I don't know what else could be the reason.
hgulyan
@Hgulyan: if you need to send <id, description> pairs, create a helper class to hold those fields, and then return a list of that helper class. Returning a plain "object" might cause trouble, indeed!
marc_s
@marc_s: Great! I changed Object array to a <param, value> class and it started to work. Thank you. You helped me a lot and sorry if I disturbed you.p.s. one last question, if you please. Is it possible to you generic in that helper class (smth like Class aaa(Of t))?
hgulyan
no, WCF doesn't play well with generic classes - everything WCF serializes back and forth between client and server must be expressed in XML schema - and XML schema doesn't understand generics, sorry. You'll have to use concrete, non-generic types.
marc_s
Ok, I got that. Thank you, Marc!
hgulyan