views:

33

answers:

2

hi there,

I have a web service. A method of this web service, returns WSSonuc class.

 [Serializable]
public class WSSonuc
{

    public int M_Durum { get; set; }
    public object M_SonucNesne { get; set; }
}

this is my Web service method:

 [WebMethod]
 [SoapHeader("_ticket", Direction = SoapHeaderDirection.InOut)]
public WSSonuc f_Dummy()
{
  WSSonuc ws = new WSSonuc();
  ws.M_Durum = 1;
  ws.M_SonucNesne = new XDocument();
  return ws;
}

I have an exception from web site when i call f_Dummy; Exception 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.

+2  A: 

XDocument isn't XML serializable. You could substitute XElement instead since this class is marked as IXMLSerializable.

If you decide to do that, it's probably important you realize the differences of these two objects. This seems like a good place to start (in addition to the links I placed above to MSDN).

Alternatively, you could fall back on good ole' XmlDocument.

Marc
A: 

When you will find proper class to pass, you need also to declare which objects could be returned (on Webservice class or method Level) using XmlIncludeAttribute

[XmlInclude(typeof(ANyDerivedType1))]
[XmlInclude(typeof(ANyDerivedType2))]
public WSSonuc f_Dummy()
Sergey Osypchuk