【问题标题】:How do I call asp.net 3.5 soap xml based webservice in javascript or jquery?如何在 javascript 或 jquery 中调用基于 asp.net 3.5 soap xml 的 web 服务?
【发布时间】:2012-08-10 15:12:17
【问题描述】:

我是 jquery 的新手,并试图在 jquery 中使用 asp.net 3.5 制作的 web 服务,但我不知道为什么我不能使用它。 我在互联网上找到的所有示例都与我正在做的相同,但我不知道代码发生了什么,

有人可以帮帮我吗?

这是我的 javascript 代码,

var soapMessage =
    '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
    <soap:Body> \
    <test xmlns="http://tempuri.org/"> \
    <param>this is a test parameter</param> \
    </test> \
    </soap:Body> \
    </soap:Envelope>';

    $.ajax({
        url: "http://localhost:50575/Service1.asmx?op=test",
        type: "POST",
        dataType: "xml",
        data: soapMessage,
        complete: hi,
        error: function (a, b, c) {
            alert("error");
        },
        contentType: "text/xml; charset=\"utf-8\""
    });

    function hi(xmlHttpRequest, status) {

        alert($(xmlHttpRequest.responseText).text());

        alert($(xmlHttpRequest.responseXML).find('Mymessage').text());

    } 

这是服务器端代码

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


    [WebMethod]
    public message test(string param)
    {
        message mymsg = new message();
        mymsg.head = "message head";
        mymsg.Mymessage = "Test string with param " + param;
        return mymsg;
    }

【问题讨论】:

  • 您在错误处理程序中为 a、b 和 c 获得什么值?
  • a 是 [object Object] b 是“错误”,c 是空的

标签: c# javascript jquery json web-services


【解决方案1】:

传递给错误处理程序的第一个对象应该包含一些有用的信息。尝试在您使用的任何调试工具中“扩展” a 。不要只是“提醒”它的价值。

具体来说,查找a.statusa.responseText。这应该让您对正在发生的事情有一个很好的了解。

【讨论】:

  • a.status 为 0,a.responseText 为空
  • id如何调试javascript?现在我正在使用警报检查结果。
  • 嗯,这很奇怪。您是否尝试将调试器附加到服务器端代码以查看服务器端是否发生任何事情?你能发布你的服务器端代码吗?
  • 我已经用服务器端代码更新了我的问题,请看一下
  • 我在服务器端附加了一个调试器,但它从来没有到达调试点,
【解决方案2】:

我建议您试一试Fiddler,这是一个很棒的网络调试工具,应该可以帮助您找出问题所在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-20
    • 1970-01-01
    相关资源
    最近更新 更多