DataTable parameter of a WebMethod?

  • Thread starter Emre Aydinceren
  • Start date
E

Emre Aydinceren

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) +5415System.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


.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,690
Latest member
MacGyver

Latest Threads

Top