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

编程入门 行业动态 更新时间:2024-10-24 01:55:22
本文介绍了如何将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的内置机制发送参数并解析返回数据. 参见 www.asp/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 www.asp/ajax/tutorials/understanding-asp-net-ajax-web-services[^]

更多推荐

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

本文发布于:2023-10-09 18:19:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1476426.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   数据   xml   Web   Service

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!