web service return type exception
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 :
Sy开发者_高级运维stem.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
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
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.
精彩评论