我有一个简单的WCF服务,它从jquery收到一些数据。
该服务在localhost上正常工作,但在IIS 7.5中托管我返回404错误
我在这里已经阅读了所有其他问题,但无法找到解决方案。
我的jquery看起来像:
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)}
});
}
我的WCF喜欢:
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; }
}
}
}
答案 0 :(得分:0)
如果您尝试在跨域调用WCF服务,则必须在WCF服务中允许跨域访问,否则您将收到错误。在这里,我正在共享参考URL以允许跨域的WCF服务
此外,我分享了另外1个博客网址,这有助于您了解jQuery AJAX和JSONP调用。这将有助于理解AJAX和JSONP方法之间的确切区别
http://www.bendewey.com/index.php/186/using-jsonp-with-wcf-and-jquery