WCF javascript call cross domain

I am new to javascript and I have a problem that is giving me hard times. I want to put in a page a tracking javascript. This script will call a wcf service to track client browser information, page visited and timestamp. The problem is that I get: "405 Method Not Allowed" error on javascript call. The service will be on another domain. Now I test this on localhost. The service is working fine because I can call it from a new page in browser. Did you experienced the same problem? How can I fix this? My javascript code is: Wcf service code: [ServiceContract(Name = "CustomersAssistantService", Namespace = "CustomersAssistantService")] public interface ICustomersAssistantService { [OperationContract] [WebGet] string DoWork(); [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] [OperationContract] string Sum(int n1, int n2); } [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class CustomersAssistantService : ICustomersAssistantService { public string DoWork() { return "work done"; } public string Sum(int n1, int n2) { return (n1 + n2).ToString(); } } Javascript call: function CallWcf1(){ var _I = this; var url = "http://localhost:58399/CustomersAssistantService.svc/customersAssistantService/"; var methodUrl = _I.serviceUrl + 'dowork'; $.ajax( { url: methodUrl, data: '', type: "GET", processData: false, contentType: "application/json", timeout: 10000, dataType: "text", // not "json" we'll parse success: function(res) { if (!callback) return; // *** Use json library so we can fix up MS AJAX dates var result = JSON2.parse(res); // *** Bare message IS result if (bare) { callback(result); return; } // *** Wrapped message contains top level object node // *** strip it off for(var property in result) { callback( result[property] ); break; } }, error: function(xhr) { if (!error) return; if (xhr.responseText) { var err = JSON2.parse(xhr.responseText); if (err) error(err); else error( { Message: "Unknown server error." }) } return; } }); } Am I doing something wrong? Thanks a lot, Radu D

以上就是WCF javascript call cross domain的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏