DataTable parameter of a WebMethod?

Discussion in 'ASP .Net Web Services' started by Emre Aydinceren, Jul 8, 2003.

  1. DataTable is not serializable, you have to put them in a
    dataset.


    >-----Original Message-----
    >Hey, here is my simple WebMethod. I'm passing a

    DataTable object to it.
    >
    > [WebMethod()]
    > public string TestMethod(DataTable dt)
    > {
    > return dt.ToString();
    > }
    >
    >Quite to my surprise, ASP.NET spew out errors to me when

    I visit the .asmx
    >file.
    >
    >I just got no idea what these messages mean and why I

    can't pass in a
    >DataTable while I can pass in a DataSet.
    >
    >Help me!
    >Server Error in '/MyWebApps/WebApplication1' Application.
    >---------------------------------------------------------

    -------------------
    >----
    >
    >Cannot serialize member

    System.ComponentModel.MarshalByValueComponent.Site
    >of type System.ComponentModel.ISite because it is an

    interface.
    >Description: An unhandled exception occurred during the

    execution of the
    >current web request. Please review the stack trace for

    more information
    >about the error and where it originated in the code.
    >
    >Exception Details: System.NotSupportedException: Cannot

    serialize member
    >System.ComponentModel.MarshalByValueComponent.Site of

    type
    >System.ComponentModel.ISite because it is an interface.
    >
    >Source Error:
    >
    >
    > An unhandled exception was generated during the

    execution of the
    >current web request. Information regarding the origin

    and location of the
    >exception can be identified using the exception stack

    trace below.
    >
    >
    >Stack Trace:
    >
    >
    >[NotSupportedException: Cannot serialize member
    >System.ComponentModel.MarshalByValueComponent.Site of

    type
    >System.ComponentModel.ISite because it is an interface.]
    > System.Xml.Serialization.TypeScope.ImportTypeDesc

    (Type type, Boolean
    >canBePrimitive, MemberInfo memberInfo) +1283
    > System.Xml.Serialization.TypeScope.GetTypeDesc(Type

    type, MemberInfo
    >source, Boolean directReference) +50
    > System.Xml.Serialization.StructModel.GetPropertyModel

    (PropertyInfo
    >propertyInfo) +54
    > System.Xml.Serialization.StructModel.GetFieldModel

    (MemberInfo memberInfo)
    >+88
    >
    >System.Xml.Serialization.XmlReflectionImporter.ImportStru

    ctLikeMapping(Struc
    >tModel model, String ns) +1534
    >
    >System.Xml.Serialization.XmlReflectionImporter.ImportStru

    ctLikeMapping(Struc
    >tModel model, String ns) +662
    >
    >System.Xml.Serialization.XmlReflectionImporter.ImportType

    Mapping(TypeModel
    >model, String ns, ImportContext context, String

    dataType, Boolean repeats)
    >+440
    >
    >[InvalidOperationException: There was an error

    reflecting type
    >'System.Data.DataTable'.]
    >
    >System.Xml.Serialization.XmlReflectionImporter.ImportType

    Mapping(TypeModel
    >model, String ns, ImportContext context, String

    dataType, Boolean repeats)
    >+1059
    >
    >System.Xml.Serialization.XmlReflectionImporter.ImportAcce

    ssorMapping(MemberM
    >apping accessor, FieldModel model, XmlAttributes a,

    String ns, Type
    >choiceIdentifierType) +8238
    >
    >System.Xml.Serialization.XmlReflectionImporter.ImportMemb

    erMapping(XmlReflec
    >tionMember xmlReflectionMember, String ns,

    XmlReflectionMember[]
    >xmlReflectionMembers) +795
    >
    >System.Xml.Serialization.XmlReflectionImporter.ImportMemb

    ersMapping(XmlRefle
    >ctionMember[] xmlReflectionMembers, String ns, Boolean

    hasWrapperElement)
    >+300
    >
    >[InvalidOperationException: There was an error

    reflecting 'dt'.]
    >
    >System.Xml.Serialization.XmlReflectionImporter.ImportMemb

    ersMapping(XmlRefle
    >ctionMember[] xmlReflectionMembers, String ns, Boolean

    hasWrapperElement)
    >+607
    >
    >System.Xml.Serialization.XmlReflectionImporter.ImportMemb

    ersMapping(String
    >elementName, String ns, XmlReflectionMember[] members,

    Boolean
    >hasWrapperElement) +108
    >
    >System.Web.Services.Protocols.SoapReflector.ImportMembers

    Mapping(XmlReflecti
    >onImporter xmlImporter, SoapReflectionImporter

    soapImporter, Boolean
    >serviceDefaultIsEncoded, Boolean rpc, SoapBindingUse

    use, SoapParameterStyle
    >paramStyle, String elementName, String elementNamespace,

    Boolean
    >nsIsDefault, XmlReflectionMember[] members, Boolean

    validate) +169
    >
    >System.Web.Services.Protocols.SoapReflector.ReflectMethod

    (LogicalMethodInfo
    >methodInfo, Boolean client, XmlReflectionImporter

    xmlImporter,
    >SoapReflectionImporter soapImporter, String defaultNs)

    +1915
    >
    >[InvalidOperationException: Method Service1.TestMethod2

    can not be
    >reflected.]
    >
    >System.Web.Services.Protocols.SoapReflector.ReflectMethod

    (LogicalMethodInfo
    >methodInfo, Boolean client, XmlReflectionImporter

    xmlImporter,
    >SoapReflectionImporter soapImporter, String defaultNs)

    +5415
    >

    System.Web.Services.Description.SoapProtocolReflector.Refl
    ectMethod()
    >+130
    >
    >System.Web.Services.Description.ProtocolReflector.Reflect

    Binding(ReflectedBi
    >nding reflectedBinding) +1818
    >

    System.Web.Services.Description.ProtocolReflector.Reflect
    () +506
    >
    >System.Web.Services.Description.ServiceDescriptionReflect

    or.ReflectInternal(
    >ProtocolReflector[] reflectors) +495
    >

    System.Web.Services.Description.ServiceDescriptionReflecto
    r.Reflect(Type
    >type, String url) +112
    >

    System.Web.Services.Protocols.DocumentationServerType..cto
    r(Type type,
    >String uri) +158
    >

    System.Web.Services.Protocols.DocumentationServerProtocol.
    Initialize()
    >+268
    >

    System.Web.Services.Protocols.ServerProtocolFactory.Create
    (Type type,
    >HttpContext context, HttpRequest request, HttpResponse

    response, Boolean&
    >abortProcessing) +106
    >
    >[InvalidOperationException: Unable to handle request.]
    >

    System.Web.Services.Protocols.ServerProtocolFactory.Create
    (Type type,
    >HttpContext context, HttpRequest request, HttpResponse

    response, Boolean&
    >abortProcessing) +205
    >
    >System.Web.Services.Protocols.WebServiceHandlerFactory.Co

    reGetHandler(Type
    >type, HttpContext context, HttpRequest request,

    HttpResponse response) +82
    >
    >[InvalidOperationException: Failed to handle request.]
    >
    >System.Web.Services.Protocols.WebServiceHandlerFactory.Co

    reGetHandler(Type
    >type, HttpContext context, HttpRequest request,

    HttpResponse response) +154
    >
    >System.Web.Services.Protocols.WebServiceHandlerFactory.Ge

    tHandler(HttpContex
    >t context, String verb, String url, String filePath) +94
    > System.Web.HttpApplication.MapHttpHandler(HttpContext

    context, String
    >requestType, String path, String pathTranslated, Boolean

    useAppConfig) +699
    >
    >System.Web.MapHandlerExecutionStep.System.Web.HttpApplica

    tion+IExecutionStep
    >..Execute() +95
    > System.Web.HttpApplication.ExecuteStep(IExecutionStep

    step, Boolean&
    >completedSynchronously) +173
    >
    >
    >
    >
    >
    >---------------------------------------------------------

    -------------------
    >----
    >
    >Version Information: Microsoft .NET Framework

    Version:1.1.4322.573; ASP.NET
    >Version:1.1.4322.573
    >
    >
    >.
    >
    Emre Aydinceren, Jul 8, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J. Babe
    Replies:
    1
    Views:
    8,303
    Kevin Spencer
    Aug 15, 2003
  2. Fredrik Rodin

    Sort a datatable and create a new datatable

    Fredrik Rodin, Feb 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    9,023
    paul.mariotti
    Sep 28, 2007
  3. Brad Quinn

    Adding an XmlNode parameter to the HelloWorld WebMethod

    Brad Quinn, Jul 31, 2003, in forum: ASP .Net Web Services
    Replies:
    4
    Views:
    128
    Lucien
    Aug 2, 2003
  4. Tim Medcalf
    Replies:
    1
    Views:
    113
  5. Mauricio Pires

    WebMethod and DataSet parameter - Help me.

    Mauricio Pires, Aug 19, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    171
    Mauricio Pires
    Aug 19, 2005
Loading...

Share This Page