如何将xml构造的数据发布到Web服务并获取返回的XML作为来自ASP,NET Web Service的响应

问题描述:

我有jquery ajax调用webservice,我正在将xml参数作为数据传递给它,当我运行代码时,流程根本没有达到webservice GetList方法,任何人都可以跟踪可能发生的问题吗?我的webconfig文件或引用任何最新的jquery文件以使代码成功运行

$ .ajax({
类型:"POST",
异步:false,
网址:"/blkseek2/JsonWebService.asmx/GetList",
数据类型:"xml",
数据:<?xml version =" 1.0?>< keyword1>" + keyword1 +</keyword1><街道名称>" +地址1+</街道名称>< lat>" + lat + </lat> lng>" + lng +</lng<半径""+ radius +"//radius" ,
contentType:应用程序/xml; charset = utf-8",
//processData:false,
失败:函数(XMLHttpRequest,textStatus,errorThrown)
{ajaxError(XMLHttpRequest,textStatus,errorThrown); },
成功:函数(xml)
{ajaxFinish(xml); }
});
});



这将是webservice文件上的webmethod.


[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]


公共XmlDocument GetList(字符串关键字1,字符串街道名称,字符串lat,字符串lng,字符串半径)
{
XmlDocument xmldoc = CreateXML(keyword1,streetname,lat,lng,radius);


返回xmldoc;

}

I have jquery ajax call to webservice for which i am passing xml parameters as data ,when i run the code the flow is not reaching webservice GetList method at all, can anyone track what may be the problem should i make any changes to my webconfig file or refer any latest jquery file to get the code running sucessfully

$.ajax({
type: "POST",
async: false,
url: "/blkseek2/JsonWebService.asmx/GetList",
datatype:"xml",
data:"<?xml version=''1.0''?><keyword1>"+keyword1+ "</keyword1><streetname>"+address1+ "</streetname><lat>"+lat+"</lat><lng>"+lng+ "</lng><radius>"+radius+"</radius>" ,
contentType: "application/xml; charset=utf-8",
// processData: false,
failure: function(XMLHttpRequest, textStatus, errorThrown)
{ ajaxError(XMLHttpRequest,textStatus, errorThrown); },
success: function(xml)
{ ajaxFinish(xml); }
});
});



This will be webmethod on webservice file .


[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]


public XmlDocument GetList(string keyword1, string streetname, string lat, string lng, string radius)
{
XmlDocument xmldoc= CreateXML( keyword1,streetname,lat,lng,radius);


return xmldoc;

}

.ajax({
类型:"POST",
异步:false,
网址:"/blkseek2/JsonWebService.asmx/GetList",
数据类型:"xml",
数据:<?xml version =" 1.0?>< keyword1>" + keyword1 +</keyword1><街道名称>" +地址1+</街道名称>< lat>" + lat + </lat> lng>" + lng +</lng<半径""+ radius +"//radius" ,
contentType:应用程序/xml; charset = utf-8",
//processData:false,
失败:函数(XMLHttpRequest,textStatus,errorThrown)
{ajaxError(XMLHttpRequest,textStatus,errorThrown); },
成功:函数(xml)
{ajaxFinish(xml); }
});
});



这将是webservice文件上的webmethod.


[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]


公共XmlDocument GetList(字符串关键字1,字符串街道名称,字符串lat,字符串lng,字符串半径)
{
XmlDocument xmldoc = CreateXML(keyword1,streetname,lat,lng,radius);


返回xmldoc;

}
.ajax({
type: "POST",
async: false,
url: "/blkseek2/JsonWebService.asmx/GetList",
datatype:"xml",
data:"<?xml version=''1.0''?><keyword1>"+keyword1+ "</keyword1><streetname>"+address1+ "</streetname><lat>"+lat+"</lat><lng>"+lng+ "</lng><radius>"+radius+"</radius>" ,
contentType: "application/xml; charset=utf-8",
// processData: false,
failure: function(XMLHttpRequest, textStatus, errorThrown)
{ ajaxError(XMLHttpRequest,textStatus, errorThrown); },
success: function(xml)
{ ajaxFinish(xml); }
});
});



This will be webmethod on webservice file .


[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]


public XmlDocument GetList(string keyword1, string streetname, string lat, string lng, string radius)
{
XmlDocument xmldoc= CreateXML( keyword1,streetname,lat,lng,radius);


return xmldoc;

}


我建​​议不要使用XML 作为参数并返回数据以从JavaScript调用Web服务方法. JSON 是更好的选择,因为它将允许您以简单的方式使用JavaScript的内置机制发送参数并解析返回数据.
参见 http://www.asp.net/ajax/tutorials/understanding-asp -net-ajax-web-services [ ^ ]
I would suggest not to use XML as parameters and return data to invoke web service methods from JavaScript. JSON is much better option for this because it will allow you to send parameters and parse the return data using JavaScript''s built in mechanism, in an easy manner.

See http://www.asp.net/ajax/tutorials/understanding-asp-net-ajax-web-services[^]