自动完成扩展器不工作

发布于 2024-11-05 03:13:29 字数 1349 浏览 8 评论 0原文

我有这项自动完成扩展服务,适用于 prefixText 的“h”和 count 的 3,并在数组中返回“hi”和“hello”:

[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);
        }
    }

服务类第一行:

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

这是 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>

一切都是正确的,但它是不工作,请帮忙。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ι不睡觉的鱼゛ 2024-11-12 03:13:29

正如您所说,您的 Web 服务和 UI 是单独的项目,因此您无法调用与托管客户端代码的页面位于不同域中的服务。这是一项安全功能,可防止恶意代码将无害的 JavaScript 重定向到万维网上的恶意内容。

解决方案

要访问外部 Web 服务,您可以在 UI 项目中构建第三个 Web 服务代理。第三个服务可以从服务器端访问外部Web服务,您可以从客户端访问这个内部Web服务。

如果您有任何疑问,请告诉我。

编辑

如果您在项目中创建了代理服务。再做一件事,在页面上添加以下代码

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

            <Services>

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

            </Services>

        </asp:ScriptManager>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文