gpt4 book ai didi

jquery - 使用 jQuery 使用 WCF 服务

转载 作者:行者123 更新时间:2023-12-01 01:37:37 26 4
gpt4 key购买 nike

我有一个简单的 WCF 服务,如下所示;

[ServiceContract]
public interface IPostService
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml)]
string CheckAlive();

还有...

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class PostService : IPostService
{
public string CheckAlive()
{
return "I'm here.";
}

在我的 MVC Web 项目中,我有一个对我的 Web 服务的服务引用。

然后我就有了这样的 jQuery 代码...

    function callWebMethod() {
$.support.cors = true;
$.ajax({
type: "GET",
url: "http://localhost:8732/Design_Time_Addresses/MyWebService/Service1/mex/CheckAlive",
data: "{}",
contentType: "application/soap+xml; charset=utf-8",

success: function (msg) {
alert("data:" + msg.d);
}, error: function(a,b,c){ alert("error:" + b + ":" + c); }
});
}

但是我总是收到“错误请求”错误。我以前从未使用过 jQuery 的 Web 服务,目前正陷入困境。

最佳答案

嘿,您必须检查 WCF 服务的端点配置。您可以查看这篇文章以获取详细信息 - http://www.codeproject.com/Articles/132809/Calling-WCF-Services-using-jQuery

关于jquery - 使用 jQuery 使用 WCF 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9493687/

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