I have a simple WCF service which recieves some data from jquery.
The service Works fine on localhost, but hosted in IIS 7.5 i returns a 404 error
I have read all the other questions here but cant find the solution.
My jquery looks like :
function SaveBannerData(bannerArray) {
$.ajax({
type: "POST",
url: "http://xxx.xxx.xx/StatService.svc/SaveBannerStat",
data: "{\"pageBanners\":" + JSON.stringify(bannerArray) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: true,
success: function (data, status, jqXHR) {},
error: function (xhr) { bannerFailed(xhr)}
});
}
And my WCF like :
namespace Comito.Portal.DataService
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class StatService
{
// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
// To create an operation that returns XML,
// add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// and include the following line in the operation body:
// WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
public void DoWork(List<BannerStat> pageBanners)
{
List<Comito.LokalPortalen.Domain.Entity.Advertice.AdverticeStat> insertData = new List<LokalPortalen.Domain.Entity.Advertice.AdverticeStat>();
foreach (BannerStat item in pageBanners)
{
Comito.LokalPortalen.Domain.Entity.Advertice.AdverticeStat adverticeStat = new LokalPortalen.Domain.Entity.Advertice.AdverticeStat();
adverticeStat.AdStatType = LokalPortalen.Domain.Enums.AdStatType.View;
adverticeStat.Advertice = item.dataAd > 0 ? new Comito.LokalPortalen.Domain.Entity.Advertice.Ad { ID = item.dataAd } : null;
adverticeStat.AdZone = item.dataZone > 0 ? new Comito.LokalPortalen.Domain.Entity.Advertice.AdZone { ID = item.dataZone } : null;
adverticeStat.StatDateTime = DateTime.Now;
insertData.Add(adverticeStat);
}
Comito.LokalPortalen.DataStore.Repositories.Advertice.AdverticeStat.UpdateAllNoSession(insertData);
return;
}
[DataContract]
public class BannerStat
{
[DataMember]
public int dataType { get; set; }
[DataMember]
public int dataZone { get; set; }
[DataMember]
public int dataAd { get; set; }
}
}
}
if you are trying to call WCF service on cross domain then you must have to allow cross domain access in your WCF service else you get error. here, i am sharing reference URL to allow WCF service for cross domain
Additionally I am share 1 more blog url which is help you to understand jQuery AJAX and JSONP call. This will more help to understand exact difference between AJAX and JSONP method
http://www.bendewey.com/index.php/186/using-jsonp-with-wcf-and-jquery
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.