我创建了一个WCF服务:从JavaScript调用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>
而且在masterPage中:
<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'。
有人知道我在做什么错?
感谢您的帮助!
你需要通过onSuccess,onFailure delgate检查这个http://stackoverflow.com/questions/712238/wcf-newbie-question-calling-methods-from-javascript我建议你关闭这个问题。 –