WCF服务404服务器上的错误,但在本地工作正常

时间:2016-01-11 17:46:32

标签: javascript asp.net wcf webforms

我已经在SO上阅读了很多其他主题,包括this onethis,但我一直无法弄清楚这个问题。

我的两个WCF服务在本地工作正常,但在服务器上时出现404错误:

enter image description here

以下是Javascript代码:

  $("#starRating").on('rating.change', function (event, value, caption) {
    var walkID = getUrlVars()["WalkID"];

    var score = $('#starRating').val();
    alert(walkID + " " + score);
    window.UserID = '<%=HttpUtility.JavaScriptStringEncode(this.User.Identity.GetUserId())%>';
    SaveRatingService.Save(score, walkID, window.UserID);

这是我的服务:

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class SaveRatingService
{
  [OperationContract]
  public void Save(string score, string walkID, string loggedInUser)
  {       
    ....
    return;
  }
}

以下是我注册的方式(MasterPage):

    <asp:ScriptManager runat="server">
        <Scripts>...</Scripts>                
      <Services>
        <asp:ServiceReference Path="~/WebServices/SaveRatingService.svc" />
      </Services> 
    </asp:ScriptManager> 

最初,我确实在ScriptManagerProxy的Javascript页面的页面上有它,但我移动它以查看是否可以解决问题。

最后这是我的母版页服务配置:

  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="DogWalks.WebServices.SaveRatingServiceAspNetAjaxBehavior">
          <enableWebScript />
        </behavior>
        <behavior name="DogWalks.WebServices.PostcodeFillAspNetAjaxBehavior">
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="DogWalks.WebServices.SaveRatingService">
        <endpoint address="" behaviorConfiguration="DogWalks.WebServices.SaveRatingServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="DogWalks.WebServices.SaveRatingService"  />
      </service>
      <service name="DogWalks.WebServices.PostcodeFill">
        <endpoint address="" behaviorConfiguration="DogWalks.WebServices.PostcodeFillAspNetAjaxBehavior" binding="webHttpBinding" contract="DogWalks.WebServices.PostcodeFill" />
      </service>
    </services>
  </system.serviceModel>

如上所述,它在本地运行良好。当我尝试按照服务的路径(第一个屏幕截图)时,路径确实会导致404错误。

在调查文件时,我看到添加了一个脚本:

enter image description here

但是,正如404错误中所提到的,它没有找到。为什么脚本会添加/js,这确实是一个不存在的目录。

0 个答案:

没有答案