开发者

web service serialization problem

开发者 https://www.devze.com 2023-01-08 01:07 出处:网络
I have a web service. A method of this web service, returns WSSonuc class. [Serializable] public class WSSonuc

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 metho开发者_开发百科d:

 [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.


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.


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()
0

精彩评论

暂无评论...
验证码 换一张
取 消