[英]How do I call asp.net 3.5 soap xml based webservice in javascript or jquery?
我是jquery的新手,并尝试使用asp.net 3.5在jquery中制作了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。 不要只是“提醒”其价值。
具体来说,寻找a.status
和a.responseText
。 这应该使您对发生的事情有个好主意。
我建议您尝试一下Fiddler ,这是一个出色的Web调试工具,应该可以帮助您发现问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.