1

I have this service for autocomplete extender that works for 'h' for prefixText and 3 for count and returns 'hi' and 'hello' in an array:

[System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public string[] GetWebUploadAutoCompleteData(string prefixText, int count)
    {
        try
        {
            DAL.DAL dal = new DAL.DAL();
            string[] returnValues = dal.GetWebUploadAutoCompleteData(prefixText, count);
            return returnValues;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }

the service class first lines:

...
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class BLL : System.Web.Services.WebService
{
...

and this is the UI:

<asp:TextBox ID="txtTest" runat="server" Width="250px"></asp:TextBox>
                <cc1:AutoCompleteExtender ID="aceTest" runat="server" CompletionSetCount="3" DelimiterCharacters=";, :"
                    ServicePath="http://localhost:7051/UploadServices/BLL.asmx" MinimumPrefixLength="2" 
                    Enabled="true" ServiceMethod="GetWebUploadAutoCompleteData" TargetControlID="txtTest">
                </cc1:AutoCompleteExtender>

everything is correct but it is not working, please help.

Harsh Baid
  • 7,199
  • 5
  • 48
  • 92
mz1378
  • 1,957
  • 4
  • 20
  • 40

1 Answers1

0

As you said that your webservice and UI are seprate project so that you can't call a service that is in a different domain than the page which hosts your client-code. This is a security feature, to prevent malicious code from redirecting your harmless javascript to something nasty on the world wide web.

Solution

To access the external web service, you can build a third web service proxy in your UI project. The third service can access the external web service from server-side, and you can access this internal web service from client.

Please let me know if you have any doubts.

EDIT

If you have created proxy service in your project.Do one more thing,add following code on the page

<asp:ScriptManager ID="ScriptManager1" runat="server">

            <Services>

                <asp:ServiceReference Path="AutoComplete.asmx" />

            </Services>

        </asp:ScriptManager>
santosh singh
  • 27,666
  • 26
  • 83
  • 129
  • I've created another service in the same folder that calling page resides, I call the original service by this service to return results. And also set the servicepath of autocompleteextender to AutoComplete.asmx in UI still nothing happens. It seems the autocxomleteextender not calling the service at all. – mz1378 May 04 '11 at 09:39
  • @mz:It's look like that problem is in Service path.Debug it in firebug it will give you exact error details. – santosh singh May 04 '11 at 09:50
  • I disabled UrlRewriter in the project and now it is working with the help of the proxy class. Thank you. – mz1378 May 08 '11 at 05:53