高手请进一个webservice的错误

tshulinzi 2005-07-01 05:25:14
报错为:未将对象引用设置到对象的实例
[WebMethod]
public SqlDataReader gettop()
{
SqlConnection myconnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand myCommand = new SqlCommand("query", myconnection);

myCommand.CommandType = CommandType.StoredProcedure;
myconnection.Open();
SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

return result;
}



检查堆栈跟踪信息:

[NullReferenceException: 未将对象引用设置到对象的实例。]
System.Xml.Serialization.XmlAttributes.GetAttr(ICustomAttributeProvider provider, Type attrType)
System.Xml.Serialization.XmlAttributes..ctor(ICustomAttributeProvider provider)
System.Xml.Serialization.TypeScope.GetEnumeratorElementType(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: 反射“gettopResult”时出错。]
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: 无法反射方法 datatest.gettop。]
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)
...全文
82 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
MyLf 2005-07-03
  • 打赏
  • 举报
回复
Webservice不支持SqlDataReader这样的类型。因为它不能序列化。
你可以使用DataSet来做。
gzlucky 2005-07-02
  • 打赏
  • 举报
回复
学习ing

SqlDataReader 是与数据库连接相关的,如果你用Web Services传递出去,Client如何使用啊?

是不是应该使用可以与Adapter无关的DataSet呢?
renyu732 2005-07-02
  • 打赏
  • 举报
回复
up

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧