简体   繁体   English

ASP.Net Web服务中的引用页面方法

[英]Referencing Page Method in ASP.Net Web Service

I am trying to access a page method from centralized module. 我正在尝试从集中式模块访问页面方法。

  • I tried putting it in a master page it didn't work 我尝试将其放在无法正常使用的母版页中

  • I tried putting it in a web service and did the following 我尝试将其放在Web服务中并执行以下操作

    1. added its path to the script manager that its existed in the master page 将其路径添加到母版页中存在的脚本管理器

    2. added a web service reference to the project 向项目添加了Web服务引用

    3. configured the web.config for the page methods 为页面方法配置了web.config

Also didn't work (kept telling me that "PageMethods is not defined" <- JavaScript error) 也没用(告诉我“未定义PageMethods” <-JavaScript错误)

  • tried to access the page methods through http request from Javascript, got server error response (500) 尝试通过来自Javascript的http请求访问页面方法,得到服务器错误响应(500)

What am I missing? 我想念什么?

I followed example #2 at this link and it worked fine (the samples appear to be broken however): http://www.asp.net/Ajax/Documentation/Live/tutorials/ExposingWebServicesToAJAXTutorial.aspx 我在此链接中遵循了示例2,但工作正常(示例似乎已损坏): http : //www.asp.net/Ajax/Documentation/Live/tutorials/ExposedWebServicesToAJAXTutorial.aspx

Here are the steps I took: 1) create a basic .asmx web service with 'HelloWorld' method 2) add the attribute [ScriptService] to the 'HelloWorld' method (and any methods in the web service that you want to call from your page script) 3) add a ScriptManager to the page, referencing the web service, and including InlineScript="true" 4) call the page from Javascript like this: 这是我采取的步骤:1)使用'HelloWorld'方法创建基本的.asmx Web服务2)将[ScriptService]属性添加到'HelloWorld'方法(以及要从Web服务中调用的任何方法)页面脚本)3)在页面上添加一个ScriptManager,引用Web服务,并包含InlineScript =“ true” 4)从Javascript调用页面,如下所示:

ServiceNamespace.ServiceClass.Method(parameters, callback);
function callback(result)
{
    alert(result);
}

The fact that you're getting a 500 error tells me that there's an error in your web service. 您收到500错误的事实告诉我您的Web服务存在错误。 I would start here: can you open your web service URL in a browser successfully, and invoke its methods? 我将从这里开始:您可以在浏览器中成功打开Web服务URL并调用其方法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM