【问题标题】:Calling from javascript to WCF从 javascript 调用 WCF
【发布时间】:2011-11-04 15:01:03
【问题描述】:

我创建了一个 WCF 服务:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace ISTL
{
    public class MatchesListService : IMatchesListService
    {
        public bool AcceptRequestToChangeMatchTime(int matchId)
        {
            return MatchesListManager.AcceptRequestToChangeMatchTime(matchId);
        }
    }
}

执行此合同:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace ISTL
{
    [ServiceContract(Namespace = "ISTL")]
    public interface IMatchesListService
    {
        [OperationContract]
        bool AcceptRequestToChangeMatchTime(int matchId);
    }
}

这是在 web.config 中:

  <system.serviceModel>
    <services>
      <service name="ISTL.MatchesListService">
        <endpoint binding="webHttpBinding" contract="ISTL.IMatchesListService"></endpoint>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior>
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

在母版页中:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    <Services>
        <asp:ServiceReference Path="~/MatchesListService.svc" />
    </Services>
</asp:ScriptManager>

我正在尝试从我的 javascript 代码中调用我的 WCF 服务:

ISTL.IMatchesListService.AcceptRequestToChangeMatchTime(matchId);

但调用 WCF 失败。 当我使用 FireBug 进行调试时,当我到达调用线路时,就会发生错误。 matchId 是一个有效值。 FireBug 识别 ISTL 命名空间,但关于 IMatchesListService 它说它的值是 'undefiend'。

有人知道我在做什么错吗?

感谢您的帮助!

【问题讨论】:

标签: ajax wcf


【解决方案1】:

你需要通过 onSuccess , onFailure delgate 检查这个WCF Newbie Question: Calling Methods from JavaScript ...我建议你关闭这个问题。

【讨论】:

  • 在发布我的问题之前,我已经阅读了该帖子中的问题。 onSuccess 和 onFailure 的代表不是强制性的。呼叫也应该在没有它们的情况下发生。但无论如何我现在尝试添加代表,问题仍然存在。
猜你喜欢
  • 1970-01-01
  • 2023-04-02
  • 2015-11-15
  • 1970-01-01
  • 2017-11-29
  • 1970-01-01
  • 2010-11-02
  • 1970-01-01
相关资源
最近更新 更多