How to customize WCF XML serialization?

Define namespaces with the XML Serialisation (or, better) Data Contract definition attributes.

Define namespaces with the XML Serialisation (or, better) Data Contract definition attributes. E.g. With XML Serialisation: Serializable, XmlRoot(namespace="example.com/eg1") public class MyClass { XmlElement(ElementName = "DataString") public string MyString { get; set; } } e.g. With Data Contract serialisation: DataContract(Namespace="http://example.com/eg2") public class MyClass { DataMember public string MyString { get; set; } } EDIT Based on the first comment, the above won't work, because the desire is to set the namespace on the SOAP wrapper around the message, not on the message itself.

OperationContractAttribute offers no control of namespaces, and I can't see any other WCF attributes at a method level. Two possibilities: (1) You may have enough control by dropping a level of abstraction and using a Message Contract.(2) Get the current WSDL for the service (using svcutil. Exe), manually adjusting it to get the namespaces you want, and then using svcutil.

Exe again to generate the code, and look at the resulting code.

Like I already stated in the question, I've tried adding an XmlRoot attribute and it didn't work. It only adds the namespace to the fields within MyClass, but not to MyClass itself. The DataContract also doesn't work, and I prefer the XmlSerializer because of renaming and order isn't important then.

– Jeroen-bart Engelen Mar 17 '09 at 10:12 I used svcutil, but without specifying a serializer and it generated a combination of MessageContract and ServiceContract with XmlSerializer. So it has one or two wrappers and I could still use the XML attributes to make it all work. – Jeroen-bart Engelen Mar 18 '09 at 18:32 @Jeroen: Please add the solution svcutil provided here for others benefit.Thanks.

– Richard Mar 18 '09 at 22:25.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions