Tag: asmx

阻止对asp.net .asmx Web服务的跨域调用

我已经构建了一个使用jQuery和JSON来使用ASP.NET .asmx Web服务来执行crud操作的应用程序。 应用程序和.asmx位于同一个域中。 我不介意人们远程使用.asmx的读取操作,但不希望人们随意删除东西! 我可以将我希望公开访问的方法和“隐藏”的方法拆分为2个Web服务。 如何将对“hidden”.asmx Web服务的调用锁定到其托管的同一域? 提前致谢。 编辑:有人可以对此发表评论,似乎有道理(来源: http ://www.slideshare.net/simon/web-security-horror-stories-presentation):Ajax可以设置Http标头,普通表格不能。 Ajax请求必须来自同一个域。 因此,“x-requested-with”“XMLHttpRequest”请求必须来自同一个域。

如何通过Jquery将数组字符串传递给Web服务?

这是我的代码: var ids = $.map($(“#container-1”).children(), function(n, i) { return n.id; }); $.ajax({ type: ‘POST’, url: ‘Loader.asmx/Active’, data: “{‘divs’:'” + ids + “‘}”, contentType: ‘application/json; charset=utf-8’, dataType: ‘json’, success: function(msg) {} });

调用共享WebMethod时出现未知Web方法exception

我正在尝试在我的网站上实现视图跟踪Web服务。 我正在使用JavaScript,因为我想从我的跟踪视图中排除任何搜索机器人。 问题是,当我尝试使用jQuery发布到我创建的Web服务时,我收到了“未知的Web方法”错误。 $(document).ready(function() { $.ajax({ type: “POST”, url: ”, data: “{‘itemType’: ‘thread’, ‘itemId’:}”, contentType: “application/json; charset=utf-8” }); }); 这是Web服务。 Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.ComponentModel _ _ _ _ Public Class ItemViewTrackingService Inherits System.Web.Services.WebService _ Public Shared Sub TrackItemView(ByVal itemType As String, ByVal itemId As Int32) If itemType.Equals(“column”, StringComparison.OrdinalIgnoreCase) Then Services.ViewTrackingService.TrackColumnView(itemId) ElseIf itemType.Equals(“thread”, StringComparison.OrdinalIgnoreCase) […]

无效的JSON原语:id

我无法使以下function正常工作。 它似乎是错误的序列化。 这是关于不同数据变体的第5次迭代。 我最初只是在做数据:{‘id’:id}就像我在使用WCF一样,但是使用ASMX它只是不起作用。 它看起来像是将数据序列化为id = 1234而不是id:1234,但我对此很新。 任何帮助,将不胜感激。 哦,我可以直接在浏览器中调用服务,它会正确返回数据,所以我知道它不是服务。 function getVentID(id) { //look up id in database and get VentID alert(‘id: ‘ + id); var jsdata = { “id”: + id} $.ajax({ type: ‘POST’, contentType: ‘application/json; charset=utf-8’, url: ‘services/UserService.asmx/getVentID’, data: jsdata, dataType: ‘json’, success: function (msg) { alert(msg.d); }, error: function (a, b, c) { […]

JSONP和ASMX Web服务

我正在试图弄清楚如何使用jQuery对ASMX Web服务进行JSONP调用。 这些只是我已经阅读过的一些页面,但没有找到任何解决方案: 如何使用jquery“jsonp”调用外部Web服务? 使用jQuery将跨域JSON发布到ASP.NET 使用JQuery访问ASP.net webservice时出错 – JSONP 使用jQuery.ajax和JSONP设置标头? http://www.codeproject.com/Articles/43038/Accessing-Remote-ASP-NET-Web-Services-Using-JSONP http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/ 等等… 这是我的示例.NET Web方法: [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void GetEmployee(string employeeId, string callback) { // Get the employee object from the Factory. Employee requestedEmployee = EmployeeFactory.GetEmployee(employeeId); if(requestedEmployee != null) { // Return the padded JSON to the caller. CrossDomainUtility.SendJsonP(callback, requestedEmployee.ToJson()); […]

从ASMX webservice读取XML数据以进行Jquery自动完成

我和ASMX Web服务无法使用。 我们争吵。 她提出了我们过去的论点。 这是一种痛苦。 我们的关系在岩石上! 我有一个ASMX Web服务,我没有使用Newtonsoft库进行序列化(解释原因在这里: http : //encosia.com/2011/04/13/asp-net-web-services-mistake-manual-json – 序列化/ )。 它看起来像这样: [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string[] GetCitiesWithState(string isoalpha2, string prefixText) { var dict = AtomicCore.CityObject.GetCitiesInCountryWithStateAutocomplete(isoalpha2, prefixText); string[] cities = dict.Values.ToArray(); return cities; } 够简单吧? 它在搜索new时返回: New Orleans, Louisiana New York, New York 我期待JSON,但经过一些阅读后,似乎我不应该尝试序列化输出 – 它应该恰好发生吗? 无论如何,所以我在前端有以下JQuery: $(‘#’).autocomplete(”, { dataType: ‘json’, […]

从ASMX返回JSON,并在Javascript中正确处理它

我意识到这里已经有很多类似的问题,但我无法想出这个问题。 我有一个Web服务(C#,。net 3.5)。 您需要了解的基本代码如下: [WebService(Namespace = “http://tempuri.org/”)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class WSMember : System.Web.Services.WebService { public WSMember () { } [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public string GetMember(string IdMember) { //Ignore the parameter for now… I will be looking up a database with it… //For now just return a minimal object: […]

将JSON发送到webmethod?

如何使用jQuery将JSON对象发送到web方法?

从Javascript调用ASMX Web服务

我想从javascript调用web服务。 这是我的代码: var method=”GetStock”; var url = “http://www.mywebsite.ro/ServiceGetStock.asmx”; $.ajax({ type: “POST”, url: url + “/GetStock”, data: “{variant_id=’1′}”, contentType: “application/json; charset=utf-8”, dataType: “json”, success: OnSuccessCall, error: OnErrorCall }); function OnSuccessCall(response) { alert(response.d); } function OnErrorCall(response) { alert(response.status + ” ” + response.statusText); } 我的ServiceGetStock.asmx代码: [WebMethod] public string GetStock(int variant_id) { try { ProductVariant variant = ProductVariantManager.GetProductVariantByID(variant_id); […]

接受List 的ASP.NET Web方法失败,“Web服务方法名称无效”。

我想创建一个接受自定义对象列表的Web方法(通过jQuery / JSON传入)。 当我在本地运行网站时,一切似乎都有效。 jQuery和ASP.NET,每个人都很高兴。 但是,当我把它放在我们的一台服务器上时,它会爆炸。 在ajax请求之后,jQuery获得500错误,响应为: System.InvalidOperationException:EditCustomObjects Web服务方法名称无效。 这是Web服务方法: [WebMethod] public void EditCustomObjects(int ID, List CustomObjectList) { // Code here } 我的jQuery代码(我认为不重要,因为错误似乎发生在Web服务级别): var data = JSON.stringify({ ID: id, CustomObjectList: customObjectList }); $.ajax({ type: “POST”, url: “/manageobjects.asmx/EditCustomObjects”, data: data, contentType: “application/json; charset=utf-8”, async: false, dataType: “json”, success: function(xml, ajaxStatus) { // stuff here } }); […]