con = New SqlConnection("workstation id=LIYANBO;packet size=4096;user id=sa;data source=localhost")
con.Open()
command = New SqlCommand("select * from SC", con)
adpot = New SqlDataAdapter(command)
adpot.SelectCommand.ExecuteNonQuery()
adpot.Fill(ds)
Dim dt As DataTable
dt = ds.Tables("SC")
con.Close()
Return dt.Rows
End Function
为什么这个WEB服务会报这样一个错呀 难到不可以返回一个datarowcollection的对象吗
“/WebService2”应用程序中的服务器错误。
--------------------------------------------------------------------------------
System.Data.DataRow 无法序列化,因为它没有默认的公共构造函数。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidOperationException: System.Data.DataRow 无法序列化,因为它没有默认的公共构造函数。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。
堆栈跟踪:
[InvalidOperationException: System.Data.DataRow 无法序列化,因为它没有默认的公共构造函数。]
System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference)
System.Xml.Serialization.TypeScope.GetTypeDesc(Type type)
System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, Boolean canBePrimitive, MemberInfo memberInfo)
System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference)
System.Xml.Serialization.TypeScope.GetTypeDesc(Type type)
System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflectionMember xmlReflectionMember, String ns, XmlReflectionMember[] xmlReflectionMembers)
System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement)
[InvalidOperationException: 反射“askResult”时出错。]
System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, String ns, Boolean hasWrapperElement)
System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String elementName, String ns, XmlReflectionMember[] members, Boolean hasWrapperElement)
System.Web.Services.Protocols.SoapReflector.ImportMembersMapping(XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, Boolean serviceDefaultIsEncoded, Boolean rpc, SoapBindingUse use, SoapParameterStyle paramStyle, String elementName, String elementNamespace, Boolean nsIsDefault, XmlReflectionMember[] members, Boolean validate)
System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs)
[InvalidOperationException: 无法反射方法 Service1.ask。]
System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo methodInfo, Boolean client, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter, String defaultNs)
System.Web.Services.Description.SoapProtocolReflector.ReflectMethod()
System.Web.Services.Description.ProtocolReflector.ReflectBinding(ReflectedBinding reflectedBinding)
System.Web.Services.Description.ProtocolReflector.Reflect()
System.Web.Services.Description.ServiceDescriptionReflector.ReflectInternal(ProtocolReflector[] reflectors)
System.Web.Services.Description.ServiceDescriptionReflector.Reflect(Type type, String url)
System.Web.Services.Protocols.DocumentationServerType..ctor(Type type, String uri)
System.Web.Services.Protocols.DocumentationServerProtocol.Initialize()
System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response)
System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
[InvalidOperationException: 无法处理请求。]
System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
[InvalidOperationException: 未能处理请求。]
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, String path, String pathTranslated, Boolean useAppConfig)
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
2 个解决方案
#1
它已经说出了问题:“System.Data.DataRow 无法序列化,因为它没有默认的公共构造函数。”
无法序列化,它就传不回来。
你可以让ask方法返回一个可序列化的对象,比如DataSet。
无法序列化,它就传不回来。
你可以让ask方法返回一个可序列化的对象,比如DataSet。
#2
<WebMethod()> Public Function ask(ByVal id As String) As DataRowCollection
con = New SqlConnection("workstation id=LIYANBO;packet size=4096;user id=sa;data source=localhost")
con.Open()
command = New SqlCommand("select * from SC", con)
adpot = New SqlDataAdapter(command)
// adpot.SelectCommand.ExecuteNonQuery()
adpot.Fill(ds,"SC")
Dim dt As DataTable
dt = ds.Tables("SC")
con.Close()
Return dt.Rows
End Function
con = New SqlConnection("workstation id=LIYANBO;packet size=4096;user id=sa;data source=localhost")
con.Open()
command = New SqlCommand("select * from SC", con)
adpot = New SqlDataAdapter(command)
// adpot.SelectCommand.ExecuteNonQuery()
adpot.Fill(ds,"SC")
Dim dt As DataTable
dt = ds.Tables("SC")
con.Close()
Return dt.Rows
End Function
#1
它已经说出了问题:“System.Data.DataRow 无法序列化,因为它没有默认的公共构造函数。”
无法序列化,它就传不回来。
你可以让ask方法返回一个可序列化的对象,比如DataSet。
无法序列化,它就传不回来。
你可以让ask方法返回一个可序列化的对象,比如DataSet。
#2
<WebMethod()> Public Function ask(ByVal id As String) As DataRowCollection
con = New SqlConnection("workstation id=LIYANBO;packet size=4096;user id=sa;data source=localhost")
con.Open()
command = New SqlCommand("select * from SC", con)
adpot = New SqlDataAdapter(command)
// adpot.SelectCommand.ExecuteNonQuery()
adpot.Fill(ds,"SC")
Dim dt As DataTable
dt = ds.Tables("SC")
con.Close()
Return dt.Rows
End Function
con = New SqlConnection("workstation id=LIYANBO;packet size=4096;user id=sa;data source=localhost")
con.Open()
command = New SqlCommand("select * from SC", con)
adpot = New SqlDataAdapter(command)
// adpot.SelectCommand.ExecuteNonQuery()
adpot.Fill(ds,"SC")
Dim dt As DataTable
dt = ds.Tables("SC")
con.Close()
Return dt.Rows
End Function