gpt4 book ai didi

c# - 为什么我的 .NET webmethod 返回一个完整的 HTML 文档而不仅仅是返回值?

转载 作者:太空狗 更新时间:2023-10-30 01:27:50 24 4
gpt4 key购买 nike

我正在尝试更熟悉 AJAX 和 Web 服务,因此我使用 VS2008 创建了最简单的 Web 服务,hello world,使用 webmethod GetPaper,并试图获取返回值“hello world”。

<%@ WebService Language="C#" Class="HelloWorld" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

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

HelloWorld : System.Web.Services.WebService {
[WebMethod]
public string GetPaper() {
return "Hello World";
}
}

http://www.linkedpapers.com/helloworld.asmx

但是,当我使用 Javascript 使用此 Web 服务时,我得到了一个完整的 HTML 页面,而不仅仅是值!

xmlRequest.onreadystatechange = ApplyUpdate;
xmlRequest.open("GET", "http://www.linkedpapers.com/helloworld.asmx?op=GetPaper", true);
xmlRequest.send();

这可能很简单,但我就是想不通!非常感谢您的帮助。

问候,

赫拉斯

编辑:还是我使用了错误的 URL?如果可以,我应该使用什么?

最佳答案

应该更像这样:

xmlRequest.onreadystatechange = ApplyUpdate;
xmlRequest.open("GET", "http://www.linkedpapers.com/helloworld.asmx/GetPaper", true);
xmlRequest.send();

还要确保配置 web.config 以允许 GET 操作:

<webServices>
<protocols>
<add name=”HttpGet”/>
</protocols>
</webServices>

关于c# - 为什么我的 .NET webmethod 返回一个完整的 HTML 文档而不仅仅是返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2177121/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com