Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending objects over WCF: send as ''XMLDocument''s?

Status
Not open for further replies.

DayLaborer

Programmer
Jan 3, 2006
347
US
I have several different types of objects that need to be returned by a "DataContract" WCF method. In other words, I must return all of the following in a method call:[tt] XMLDocument, List<MyCustomObject>, ADifferentCustomObject[/tt]. I need to do this to minimize round-trip calls to the method.

Two questions:
1) Is there a better way to return them other than lumping them into an "XMLDocument" object? (I think the idea of an Object[] is not so good...)

2) If an "XMLDocument" object is, in fact, the best object type to return, how do I "squish" my custom objects as well as standard types (strings, ints, etc.) into an "XMLDocument"? Am I supposed to manually concatenate the XML nodes?

As you can tell, I'm new to both WCF and XML.

Thanks in advance,
Eliezer
 
Can you not create a meta object that has an XmlDocument, a List<> and so on, and return that?

Why do you think that you will need to minimize the round trips to the method, how big are these items, how often are they being called etc?

Is there any facility for caching the data...

We need to know more before we can really give you any advice to this..

 
Yes, I can make a meta object - but how do I "flatten" that meta-object into an XmlDocument object?
 
Im confused now, does your data contract explicitly state that the method call return parameter is an Xml Document, or does it return your 'meta object' and are you having problems in getting wcf to create the object ?

Being as you state that it can return an Xml Document, a List of Custom objects and a different object, I am assuming that it is creating the wire object.

I'll go back to first principles, so apologies if you have done this, best to check before we go too far :)

Have you decorated the class with the correct attributes ?

i.e.

[DataContract(Namespace="]
public class MetaClass
{
XmlDocument _xDoc;
List<ObjectA> _listObject;
ObjectB _objectB;

[DataMember(IsRequired=true, order=1)]
public XmlDocument XDoc
{
//get, set omitted to save typing
}

[DataMember(IsRequired=true, order=2)]
public ObjectA[] ListObjectA
{
//get, set omitted to save typing
}

[DataMember(IsRequired=true, order=2)]
public ObjectB InstanceOfObjectB
{
//get, set omitted to save typing
}

}

its been a while since I used wcf, but I seem to recall that you need to explicitly declare the data members that are to be serialised.

Hope that helps, else post back..

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top