[英]Calling WCF Service from JavaScript using AJAX through JQuery
I'm trying to call a WCF Service located locally through JavaScript. 我正在尝试通过JavaScript调用位于本地的WCF服务。 Here is a sample of the WCF Service.
这是WCF服务的示例。
public string GetMarkers()
{
List<Marker> lstMarkers = new MarkerMgr().GetMarkers().ToList();
List<Marker> lstMark = new List<Marker>();
foreach (Marker m in lstMarkers)
{
Marker marker = new Web_Service.Marker();
marker.Id = m.Id;
marker.Latitude = m.Latitude;
marker.Longitude = m.Longitude;
marker.Title = m.Title;
marker.Description = m.Description;
marker.Icon = m.Icon;
lstMark.Add(marker);
}
JavaScriptSerializer jss = new JavaScriptSerializer();
jss.MaxJsonLength = Int32.MaxValue;
return jss.Serialize(lstMark);
}
and this is the function which I'm using to call the WCF Service. 这就是我用来调用WCF服务的函数。
function getMarkers() {
var markers = null;
$.ajax({
async: true,
type: "GET",
url: "http://localhost:61892/Service.svc/GetMarkers", // the URL of the controller action method
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: true,
success: function (result) {
alert(result);
markers = result;
},
error: function (req, status, error) {
alert(error);
}
});
return markers;
}
I've tried many different approaches to solve this but they weren't successful. 我尝试了许多不同的方法来解决此问题,但没有成功。 From all the research I've done I think its something about the localhost.
根据我所做的所有研究,我认为这与本地主机有关。 Anyone has an idea?
有人有主意吗? Thanks a lot.
非常感谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.