WCF DataContract / ServiceOperation Using .NET Type XmlDocument

im just curious about the data contracts that need to be sent through the wiring in the WCF connection. I know for the sake of interoperability, it is not recommended (maybe not even allowed?) to send native .NET types as part of the data contract.

I want to have a service that accepts, like type input ServiceOperation, .NET XmlDocument. If I were to create a wrapper class (which would be marked with an attribute DataContract) that contains the type XmlDocument(which will be marked with the attribute DataMember) and use it as a parameter for ServiceOperation- Would that be legal / possible?

How can I ensure interoperability while maintaining type convenience XmlDocument? Could it be a better design choice to take stringas a parameter for ServiceOperation, and then create an instance XmlDocumentusing a method XmlDocument.LoadXml(string)on the service side?

welcomes any help / submissions / comments, I'm just starting to deal with wcf, so I just want to clarify any confusion in my head before I get into the head first in creating a service.

THANK!

+3
source share
5 answers

You will need to add the [XmlSerializerFormat] attribute.

So (without using Datacontract, although you can use that too):

[ServiceContract (Namespace = "urn: SerializationTest")]

[XmlSerializerFormat]

IBlah public interface

{

[OperationContract]

XmlDocument Returnxmldoc();

}

+2

"", / .

.NET. : "" ?

, System.Xml.XmlDocument... :)

"XElement", ... ( System.Xml.Linq).

+1

, CLR, KnownType.

0

, DLL ( , ). , - A B, , dll . , BTW VS 2008 . .NET 3.0, , svcutil.

, .

, .

0

Do you have an XSD for your XML document? If it is so easy to create a composite DataContract structure using svcutil.exe (svcutil.exe / dconly schemaName.xsd). At this point you have the option of using DataContractSerializer to move between your document and the XML-DataContracts composite, which can be used in your service interface and your implementation, if you do this.

In addition, I agree with previous posters (s) with YAGNI's compatibility comment.

JB http://jb-brown.blogspot.com

0
source

All Articles