views:

40

answers:

2

Hi there,

I have a web service and its methods return a class which is name WSResult. WSResult has 2 properties. One of property's type is int and the other one's type is object. I want to return some different type with this second property. you can see my WSREult

[Serializable]
public class WSResult
{

    public int M_Status { get; set; }
    public object M_ResultObject { get; set; }
}

But when i want to return DataSet or another serializable object with M_ResultObject, i have an error. Error is :

System.Web.Services.Protocols.SoapException: Server was unable to process request.     
---> System.InvalidOperationException: 
        There was an error generating the XML document. 
---> System.InvalidOperationException: 
        The type System.Xml.Linq.XDocument was not expected. 
        Use the XmlInclude or SoapInclude attribute to specify types that are not 
        known statically

How can i pass an object which i retrieved from other web services or that i generated from my serializable classes inside M_ResultObject property ?

KR

A: 

Have you tried marking the M_ResultObject property with XmlInclude/SoapInclude as the error message hints at?

[XmlInclude(typeof(...))]
public object M_ResultObject { get; set; }

You must tell the relevant serializer what the possible types are for M_ResultObject. You can specify multiple attributes if there are multiple different objects that can be returned.

Jamiec
Only `[XmlInclude]` is necessary.
John Saunders
Why can't i send an object that i retrieved from other web service inside this class as object type?
cagin
@cagin - because object is not implicitly serializable, the serializer must know what its serializing.
Jamiec
@Jamiec, ok. I want to make the situation clearer. I have web service which return objects. These objects are generate by using its own class library. And this library connects the other web services and retrieves objects(which are of course Serializable) and passes them to the web service to send back to the client. One object is coming other web services but my main web serivice can't send these objects back to the client... Do you think this is logical?
cagin
A: 

My manager developer solved this problem and i want to share with you. We should put

[XmlInclude(typeof(...))]

on .asmx web service and update web service reference from client side.

KR

cagin