views:

31

answers:

3

Hi there,

I need to pass an XML document to the web service. Is it possible to simply specify a contract with a method, say

void Method(XmlDocument myDocument);

and implement it in a standard way? I need to keep in my the Silverlight functionality, thus I want to avoid writing the XML to a stream... Is it a good approach?

Thank you in advance for the hints and replies!

Cheers

+1  A: 

If i recall correctly, XmlDocument is not serializable (which is required for a webservice).

The easiest way would be to write the xml document to a string ( xml), send this to your webservice and there you can deserialize it again to an XmlDocument

Noctris
Do you think of creating the contract e.g. void M(string myXml); and passing the XML as the string back and forth?
Jamie
Yup.. but i do agree with Marc_s.. take a good look at why you are passing the whole xml before doing so.. WCF does the whole serialization and deserialize for you if the object is serializable..
Noctris
A: 

If you must pass in that XML document, pass it as a string. But the whole point of the WCF services is that you don't have to fiddle around with XML yourself - you just call the method and pass it some parameters (ints, strings, your own types) and the WCF runtime handles all the thorny XML stuff for you....

marc_s
I rather need to pass my XML, and then use it in Silverlight, which has a very limited XML (serialization/deserialization) functionality. Thus I'm afraid I need to pass it as a string...
Jamie
A: 

I've personally done this (forced too...). WCF has string buffer and string deserialization limits in the WCF binding which you need to override if you are sending anything of size through the interface.

But that said, if your requirement is to simply send XML then create a class, decorate it with the WCF XML attributes and then declare your interface to send them.

If you are interoperating with an existing service, you should be able to use the WCF service tools in the windows SDK to create a WCF binding against the service for you.

Spence
Hi Spence, you wrote "But that said, if your requirement is to simply send XML then create a class, decorate it with the WCF XML attributes and then declare your interface to send them.". It sounds interesting, could you give some example? Please keep in mind, that I need to conform to Silverlight, which does NOT support XmlSerializer or such stuff...
Jamie
http://msdn.microsoft.com/en-us/library/ms733127.aspx
Spence
THis is a little more like a tutorial for you: http://msdn.microsoft.com/en-us/library/ms733811.aspx
Spence