自动完成扩展器不工作
我有这项自动完成扩展服务,适用于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所说,您的 Web 服务和 UI 是单独的项目,因此您无法调用与托管客户端代码的页面位于不同域中的服务。这是一项安全功能,可防止恶意代码将无害的 JavaScript 重定向到万维网上的恶意内容。
解决方案
要访问外部 Web 服务,您可以在 UI 项目中构建第三个 Web 服务代理。第三个服务可以从服务器端访问外部Web服务,您可以从客户端访问这个内部Web服务。
如果您有任何疑问,请告诉我。
编辑
如果您在项目中创建了代理服务。再做一件事,在页面上添加以下代码
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