2011-11-03 36 views
0

我创建了一个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'。

有人知道我在做什么错?

感谢您的帮助!

+1

你需要通过onSuccess,onFailure delgate检查这个http://stackoverflow.com/questions/712238/wcf-newbie-question-calling-methods-from-javascript我建议你关闭这个问题。 –

回答

0

你需要传递成功,onFailure delgate检查这个WCF Newbie Question: Calling Methods from JavaScript ...我会建议你关闭这个问题。

+0

我在发布我的问题之前已阅读该帖子中的问题。 onSuccess和onFailure的代表不是强制性的。呼叫也应该没有他们。 但无论如何,我尝试添加代表现在,问题依然存在。 – Alon

+0

你能分享你的JavaScript客户端代码吗? –