Monday, March 26, 2012

Ajax AutoComplete Problem

I have been trying to get the AutoComplete work without success. (many Days)

I have a deveplement Server 2003, XP workstation with VS2005 and IE7, and have check this with a workstation with Win98&IE6

I am using the demo from the Ajax.net video's

I have install the lastest ajax onto the server and the bin directory has: AjaxControlToolkit;AjaxControlToolkit.dll;AjaxControlToolkit.dll.refresh;AJAXExtensionsToolbox.dll;BuildVsi.dll;JavaScriptCommentStripper.dll;System.Web.Extensions.Design.dll;System.Web.Extensions.dll;Tools.dll;Tools.netmodule.

I can get things like the CollapsiblePanelExtender working, The demo on the ajax web site works.

The page displays as expected, but when I type the 3rd character, nothing happens

Filddler gives me an error 500, on the 3rd 'a'

I also had to create a folder named 'GetCompletionList' with a copy of autocomplete.asmx in it to fix an error 404 that fiddler gave me, which may be anther issuse.

I can call the web service and get results from it and '/js' gets me the option to download the JavaScript.

=====Fiddler=====

{"prefixText":"aaa","count":10}

-----------

HTTP/1.1 500 Internal Server Error

Date: Sun, 29 Apr 2007 10:35:28 GMT

Server: Microsoft-IIS/6.0

MicrosoftOfficeWebServer: 5.0_Pub

X-Powered-By: ASP.NET

X-AspNet-Version: 2.0.50727

Cache-Control: private

Content-Type: application/soap+xml; charset=utf-8

Content-Length: 1666

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><soap:Fault><soap:Code><soap:Value>soap:Receiver</soap:Value></soap:Code><soap:Reason><soap:Text xml:lang="en">System.Web.Services.Protocols.SoapException: Server was unable to process request. --> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.

at System.Xml.XmlTextReaderImpl.Throw(Exception e)

at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)

at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()

at System.Xml.XmlTextReaderImpl.ParseDocumentContent()

at System.Xml.XmlTextReaderImpl.Read()

at System.Xml.XmlTextReader.Read()

at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read()

at System.Xml.XmlReader.MoveToContent()

at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent()

at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement()

at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest()

at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message)

at System.Web.Services.Protocols.SoapServerProtocol.Initialize()

at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

-- End of inner exception stack trace --</soap:Text></soap:Reason><soap:Detail /></soap:Fault></soap:Body></soap:Envelope>

=====Default.aspx=====

<%

@dotnet.itags.org.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default" %>

<%

@dotnet.itags.org.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>Ajax Test</title>

</

head>

<

body><formid="form1"runat="server"><asp:ScriptManagerID="ScriptManager1"runat="server"><Services><asp:ServiceReferencePath="AutoComplete.asmx"/></Services></asp:ScriptManager><asp:TextBoxID="TextBox1"runat="server"></asp:TextBox><br/><cc1:AutoCompleteExtenderid="AutoCompleteExtender1"runat="server"ServiceMethod="AutoComplete.asmx"ServicePath="GetCompletionList"TargetControlID="TextBox1"></cc1:AutoCompleteExtender></form>

</

body>

</

html>

=====AutoComplete.asmx=====

<%

@dotnet.itags.org.WebServiceLanguage="VB"CodeBehind="~/App_Code/AutoComplete.vb"Class="AutoComplete" %>

=====App_Code/AutoComplete.vb=====

Imports

System.Web

Imports

System.Web.Services

Imports

System.Web.Services.Protocols

Imports

System.Collections.Generic

'from line 10( before ScriptService): <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

<WebService(Namespace:=

"http://tempuri.org/")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

<System.Web.Script.Services.ScriptService()> _

Public

Class AutoCompleteInherits System.Web.Services.WebService

<WebMethod()> _

PublicFunction GetCompletionList(ByVal prefixTextAsString,ByVal countAsInteger)AsString()Dim c1AsCharDim c2AsCharDim c3AsCharIf (count = 0)Then

count = 10

EndIfDim rndAsNew Random()Dim itemsAsNew List(OfString)For iAsInteger = 1To count

c1 =

CStr(rnd.Next(65, 90))

c2 =

CStr(rnd.Next(97, 122))

c3 =

CStr(rnd.Next(97, 122))

items.Add(prefixText + c1 + c2 + c3)

Next iReturn items.ToArray()EndFunction

End

Class

=====Web.config=====

<?

xmlversion="1.0"?>

<

configuration>

<

configSections>

<

sectionGroupname="system.web.extensions"type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

<

sectionGroupname="scripting"type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

<

sectionname="scriptResourceHandler"type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"requirePermission="false"allowDefinition="MachineToApplication"/>

<

sectionGroupname="webServices"type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">

<

sectionname="jsonSerialization"type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"requirePermission="false"allowDefinition="Everywhere"/>

<

sectionname="profileService"type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"requirePermission="false"allowDefinition="MachineToApplication"/>

<

sectionname="authenticationService"type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"requirePermission="false"allowDefinition="MachineToApplication"/>

</

sectionGroup>

</

sectionGroup>

</

sectionGroup>

</

configSections>

<

system.web>

<!--

MarkRoss: Next line added to fix remote error message-->

<

customErrorsmode="Off"/>

<

webServices>

<

protocols>

<

addname="HttpGet"/>

<

addname="HttpPost"/>

</

protocols>

</

webServices>

<

pages>

<

controls>

<

addtagPrefix="asp"namespace="System.Web.UI"assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

</

controls>

</

pages>

<!--

Set compilation debug="true" to insert debugging

symbols into the compiled page. Because this

affects performance, set this value to true only

during development.

-->

<

compilationdebug="false">

<

assemblies>

<

addassembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<

addassembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<

addassembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/></assemblies>

</

compilation>

<

httpHandlers>

<

removeverb="*"path="*.asmx"/>

<

addverb="*"path="*.asmx"validate="false"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<

addverb="*"path="*_AppService.axd"validate="false"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<

addverb="GET,HEAD"path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"validate="false"/>

</

httpHandlers>

<

httpModules>

<

addname="ScriptModule"type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

</

httpModules>

</

system.web>

<

system.web.extensions>

<

scripting>

<

webServices>

<!--

Uncomment this line to customize maxJsonLength and add a custom converter-->

<!--

<jsonSerialization maxJsonLength="500">

<converters>

<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>

</converters>

</jsonSerialization>

-->

<!--

Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate.-->

<!--

<authenticationService enabled="true" requireSSL = "true|false"/>

-->

<!--

Uncomment these lines to enable the profile service. To allow profile properties to be retrieved

and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and

writeAccessProperties attributes.

-->

<!--

<profileService enabled="true"

readAccessProperties="propertyname1,propertyname2"

writeAccessProperties="propertyname1,propertyname2" />

-->

</

webServices>

<!--

<scriptResourceHandler enableCompression="true" enableCaching="true" />

-->

</

scripting>

</

system.web.extensions>

<

system.webServer>

<

validationvalidateIntegratedModeConfiguration="false"/>

<

modules>

<

addname="ScriptModule"preCondition="integratedMode"type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

</

modules>

<

handlers>

<

removename="WebServiceHandlerFactory-Integrated"/>

<

addname="ScriptHandlerFactory"verb="*"path="*.asmx"preCondition="integratedMode"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<

addname="ScriptHandlerFactoryAppServices"verb="*"path="*_AppService.axd"preCondition="integratedMode"type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<

addname="ScriptResource"preCondition="integratedMode"verb="GET,HEAD"path="ScriptResource.axd"type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

</

handlers>

</

system.webServer>

</

configuration>

I have resolved this

in:-

<cc1:AutoCompleteExtenderid="AutoCompleteExtender1"runat="server"ServiceMethod="AutoComplete.asmx"

ServicePath="GetCompletionList"TargetControlID="TextBox1">

</cc1:AutoCompleteExtender>

I had theServiceMethod& ServicePath attributes back to front

Note: Using Fiddler helped, couldn't see this problem initially due to its simplicity

"I also had to create a folder named 'GetCompletionList' with a copy of autocomplete.asmx in it to fix an error 404 that fiddler gave me, which may be anther issuse."

No comments:

Post a Comment