Saturday, March 24, 2012

How can I use bridging with AutoCompleteExtender?

I would like to use external webservice to get data in AutoCompleteExtender instead of having local .txt file as specified in ATLAS documentation/exmples.

.asbx is correctly registered in IIS. I have created a bridge file ServerAutoComplete.asbx like...

<?

xmlversion="1.0"encoding="utf-8" ?>
<bridgenamespace="Samples.AspNet"className="BridgeServerAutoComplete" >
<proxytype="CatalogReader, App_Code" />
<methodname="GetWordList">
<input>
<parametername="prefixText"/>
<parametername="count" />
</input>
</method>
</bridge>

where CatalogReader is class of my webservice which is hosted on another server.

I have following settings in my ServerAutoComplete.aspx page forScriptManagerandAutoCompleteExtender.

<atlas:ScriptManagerID="AtlasPage1"runat="server">
<Services>
<atlas:ServiceReferencePath="~/ServerAutoComplete.asbx"/>
</Services>
</atlas:ScriptManager>

...

<

asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

<atlas:AutoCompleteExtenderID="autoComplete1"runat="server">
<atlas:AutoCompletePropertiesEnabled="True"MinimumPrefixLength="1"ServiceMethod="GetWordList"ServicePath="ServerAutoComplete.asbx"TargetControlID="TextBox1"/>
</atlas:AutoCompleteExtender>

...

Now when I run ServerAutoComplete.aspx page I am not getting any AutoComplete words.

My question is how can I set this whole set-up working? How can I set parameters of webservice method from AutoCompleteProperties?

Am I missing any step?

Thanks,

Vishant

Hi Vishant,

So the easiest way for you to pass parameters to the bridge in this scenario would be on the query string.

First you'll need to enable get for your bridge service, which you can do by adding:

<methodname="GetWordList" getEnabled="true">

Now you can hit the bridge using a url like: http:yourserver/ServerAutoComplexe.asbx?mn=GetWordList&prefixText=<text>&count=<count>, you should verify that using the browser and make sure that you get some JSON back...

That being said, I'm not sure there's an easy to pass these on the query string from AutoComplete. The best option would be to add a <binding> for the serviceUrl of the autocompleteproperteries where you specify a custom javascript transform method, i.e. transform="GetServiceUrl", and this method returns "ServerAutoComplete.asbx?prefixText="+document.getElementById("TextBox1").value and you also add the count parameter in there as well.

That should work, I think...

Hope that helps,
-Hao


Hi Hao,

Thanks for your reply.

I enabled "get" on my bridge service as you have mentioned but when I hit browser with "http:yourserver/ServerAutoComplexe.asbx?mn=GetWordList&prefixText=<text>&count=<count>" it does not give any JSON. Is this the exact syntax should I use?

I also could not find</binding>tag anywhere in documentation. Is this new tag forAutoCompleteProperties? I put it as shown below but no result.Does this syntax is correct?

<atlas:AutoCompletePropertiesEnabled="True"MinimumPrefixLength="1"ServiceMethod="GetWordList"ServicePath="~/ServerAutoComplete.asbx"TargetControlID="TextBox1">
<bindingtransform="GetServiceUrl"></binding>
</atlas:AutoCompleteProperties>

I know I am asking too much but I am new to ATLAS and JSON. It would be great if you can please provide step by step instruction or syntax?

Vishant


So you'll want to hit the real URL of your server with the browser, not http:yourserver..., you'll also want to give real data to your service.

Taking a step back, what is does your ServerAutoComplete.asbx look like?

But the real situation is that currently the AutoCompleteExtender does not really have a good story for hitting a bridge rather than an explicit webservice as its expecting, the option I listed above is more of a workaround/hack given the existing situation.

Hope that helps,
-Hao

No comments:

Post a Comment