Re: Add Web Reference Error
- From: "Ross" <Ross@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 24 Sep 2005 04:23:02 -0700
Thanks Carsten
I'll give the dataset a go.
Kind regards
Ross Petersen
"CT" wrote:
> Ross,
>
> You will not have this working, because the DataReader needs an open
> connection when you retrieve the items in it. Once it's returned from the
> Web service, the Web service forgets all about it and the connection is
> closed. You should consider using the DataSet or if you're using VB 2005, a
> DataTable to return the rows, as these classes are serializable.
>
> --
> Carsten Thomsen
> Enterprise Development with VS .NET, UML, AND MSF
> http://www.apress.com/book/bookDisplay.html?bID=105
> Communities - http://community.integratedsolutions.dk
>
> "Ross" <Ross@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:E0B626A3-C6A7-4DC1-A9E0-9593A2C28464@xxxxxxxxxxxxxxxx
> > Hi folks
> >
> > I have a <WebMethod> public function called GetCountriesForCountryStart
> > that
> > has a single input parameter (Varchar 50) and returns a SQLDataReader.
> >
> > The relevant code is as follows:
> >
> > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> >
> > <WebMethod()> Public Function GetCountriesForCountryStart(ByVal
> > strCountryStart As String) As SqlDataReader
> >
> > Dim cn As SqlConnection
> > Dim strInfo As String
> > Dim cmd As SqlCommand
> > Dim prmTemp As SqlParameter
> > Dim intResult As Integer
> > Dim rdCountries As SqlDataReader
> >
> > strInfo =
> > "server=(local);uid=dbo;pwd=;database=FusionCommunityVolunteerSystem;Persist
> > Security Info=False;Integrated Security=SSPI"
> >
> > 'open connection to DB
> > Try
> > cn = New SqlConnection
> > cn.ConnectionString = strInfo
> > cn.Open()
> >
> > 'no errors in opening connection, so now create command
> > 'to run the SP "procCountryGetForNameStart"
> > Try
> >
> > cmd = New SqlCommand
> >
> > With cmd
> > .Connection = cn
> > .CommandType = CommandType.StoredProcedure
> > .CommandText = "procCountryGetForNameStart"
> >
> > prmTemp = .Parameters.Add("@namestart",
> > SqlDbType.VarChar, 50)
> > prmTemp.Direction = ParameterDirection.Input
> > prmTemp.Value = strCountryStart
> >
> > 'execute the SP - this returns 2 columns - CountryID &
> > CountryName
> > rdCountries = .ExecuteReader()
> >
> > Return rdCountries
> >
> > End With
> > Catch ex As Exception
> >
> > End Try
> >
> > Catch ex As Exception
> >
> > Finally
> > 'check to see if connection is open & if so, then close it
> > If cn.State = ConnectionState.Open Then
> > cn.Close()
> > End If
> > End Try
> > End Function
> >
> > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> >
> > I also have a web form that has a dropdownlist box that I want to populate
> > with the output from the DataReader based upon a entry in a text box on
> > the
> > same form.
> >
> > However, when I try to create a web reference from the project for the
> > form
> > to the project that contains the method GetCountriesForCountryStart I
> > receive
> > the following error:
> >
> > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> >
> > "System.NullReferenceException: Object reference not set to an instance of
> > an object"
> >
> > The stack trace seems to be pointing to an error in the above function &
> > is
> > as follows:
> >
> > [NullReferenceException: Object reference not set to an instance of an
> > object.]
> > System.Xml.Serialization.XmlAttributes..ctor(ICustomAttributeProvider
> > provider) +105
> > System.Xml.Serialization.TypeScope.GetEnumeratorElementType(Type type)
> > +107
> > System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, Boolean
> > canBePrimitive, MemberInfo memberInfo) +1463
> > System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo
> > source, Boolean directReference) +50
> >
> > System.Xml.Serialization.XmlReflectionImporter.ImportMemberMapping(XmlReflectionMember
> > xmlReflectionMember, String ns, XmlReflectionMember[]
> > xmlReflectionMembers)
> > +34
> >
> > System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[]
> > xmlReflectionMembers, String ns, Boolean hasWrapperElement) +300
> >
> > [InvalidOperationException: There was an error reflecting
> > 'GetCountriesForCountryStartResult'.]
> >
> > System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(XmlReflectionMember[]
> > xmlReflectionMembers, String ns, Boolean hasWrapperElement) +607
> >
> > System.Xml.Serialization.XmlReflectionImporter.ImportMembersMapping(String
> > elementName, String ns, XmlReflectionMember[] members, Boolean
> > hasWrapperElement) +108
> >
> > 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) +169
> >
> > System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo
> > methodInfo, Boolean client, XmlReflectionImporter xmlImporter,
> > SoapReflectionImporter soapImporter, String defaultNs) +2927
> >
> > [InvalidOperationException: Method
> > CountriesService.GetCountriesForCountryStart can not be reflected.]
> >
> > System.Web.Services.Protocols.SoapReflector.ReflectMethod(LogicalMethodInfo
> > methodInfo, Boolean client, XmlReflectionImporter xmlImporter,
> > SoapReflectionImporter soapImporter, String defaultNs) +5494
> > System.Web.Services.Description.SoapProtocolReflector.ReflectMethod()
> > +130
> >
> > System.Web.Services.Description.ProtocolReflector.ReflectBinding(ReflectedBinding
> > reflectedBinding) +1966
> > System.Web.Services.Description.ProtocolReflector.Reflect() +509
> >
> > System.Web.Services.Description.ServiceDescriptionReflector.ReflectInternal(ProtocolReflector[]
> > reflectors) +495
> > System.Web.Services.Description.ServiceDescriptionReflector.Reflect(Type
> > type, String url) +112
> > System.Web.Services.Protocols.DocumentationServerType..ctor(Type type,
> > String uri) +158
> > System.Web.Services.Protocols.DocumentationServerProtocol.Initialize()
> > +269
> > 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.CoreGetHandler(Type
> > type, HttpContext context, HttpRequest request, HttpResponse response) +82
> >
> > [InvalidOperationException: Failed to handle request.]
> >
> > System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type
> > type, HttpContext context, HttpRequest request, HttpResponse response)
> > +154
> >
> > System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext
> > context, String verb, String url, String filePath) +94
> > System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
> > requestType, String path, String pathTranslated, Boolean useAppConfig)
> > +698
> >
> > System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
> > +95
> >
> > xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> >
> > So, I was wondering if there is something fundamentally wrong with my
> > whole
> > approach, or just something wrong with the code for the procedure or
> > something else?
> >
> > Kind regards
> >
> > Ross Petersen
>
>
>
.
- References:
- Re: Add Web Reference Error
- From: CT
- Re: Add Web Reference Error
- Prev by Date: Re: Add Web Reference Error
- Next by Date: Re: Urgent pls: WRN: Assembly binding logging is turned OFF -- HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1
- Previous by thread: Re: Add Web Reference Error
- Next by thread: Re: Urgent pls: WRN: Assembly binding logging is turned OFF -- HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1
- Index(es):
Relevant Pages
|