简体   繁体   English

调用WCF服务在本地工作,但不在服务器404上工作

[英]Call to WCF Service works local but not on server 404

I have a simple WCF service which recieves some data from jquery. 我有一个简单的WCF服务,它从jquery接收一些数据。

The service Works fine on localhost, but hosted in IIS 7.5 i returns a 404 error 该服务可以在localhost上正常运行,但是托管在IIS 7.5中,我返回404错误

I have read all the other questions here but cant find the solution. 我在这里已经阅读了所有其他问题,但是找不到解决方案。

My jquery looks like : 我的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)}
});

} }

And my WCF like : 和我的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; }
    }
}

} }

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. 如果您尝试在跨域上调用WCF服务,则必须必须在WCF服务中允许跨域访问,否则会出错。 here, i am sharing reference URL to allow WCF service for cross domain 在这里,我共享参考URL,以允许跨域使用WCF服务

http://www.dotnet-tricks.com/Tutorial/wcf/X8QN260412-Calling-Cross-Domain-WCF-Service-using-Jquery.html http://www.dotnet-tricks.com/Tutorial/wcf/X8QN260412-Calling-Cross-Domain-WCF-Service-using-Jquery.html

Additionally I am share 1 more blog url which is help you to understand jQuery AJAX and JSONP call. 另外,我还要再分享1个博客网址,这可以帮助您了解jQuery AJAX和JSONP调用。 This will more help to understand exact difference between AJAX and JSONP method 这将有助于理解AJAX和JSONP方法之间的确切区别。

http://www.bendewey.com/index.php/186/using-jsonp-with-wcf-and-jquery http://www.bendewey.com/index.php/186/using-jsonp-with-wcf-and-jquery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM