Asp.Net-WCF Javascript调用的ServiceReference问题. [英] Asp.Net - Problem with ServiceReference of WCF Javascript call.

查看:65
本文介绍了Asp.Net-WCF Javascript调用的ServiceReference问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用asp:ServiceReference从Javascript调用应用程序的WCF函数.我在Aspx页面中声明了ServiceReference-"MyPage.aspx",如下所示.

Hi,

I am calling WCF function of my application from Javascript using asp:ServiceReference. I have declared ServiceReference in my Aspx page - "MyPage.aspx" as below.

<asp:ScriptManager ID="ScriptManager1" runat="server">    
 <Scripts>
  <asp:ScriptReference Path="~/Scripts/script.js"/>
  <asp:ScriptReference Path="~/Scripts/jquery.js"/>
     
 </Scripts>        

 <Services>
  <asp:ServiceReference Path="~/Services/MyService.svc" />
        
 </Services>

</asp:ScriptManager>



我在Javascript中调用WCF方法MyWCFMethod,如下所示.



I am calling WCF method MyWCFMethod in my Javascript as below.

function BeforeNavigate()
{
     var isConfirm = confirm("Do you want to Navigate?");
     if (isConfirm ) 
     {
       CCRClientService.MyWCFMethod(frmSuccess, frmFail, null);
       return false;
     }
}

function frmSuccessUnlock(result) { return true; }
function frmFail(result) { return false; }



当用户尝试导航到其他页面时,将调用Javascript函数BeforeNavigate.当我进入"MyPage.aspx"并在几秒钟后导航到其他页面时,我的WCF方法被成功调用.但是,当我一进入"MyPage.aspx"就非常快速地导航时,则不会调用我的WCF方法.

知道为什么在进入"MyPage.aspx"后导航时为什么没有调用WCF方法吗?

干杯
Rais



Javascript function BeforeNavigate is called when user tries to navigate to other pages. When I come on "MyPage.aspx" and navigate to some other page after few seconds, my WCF method gets call successfully. But when navigate very quickly as soon as I come on "MyPage.aspx", then my WCF method does not get called.

Any idea why WCF method does not getting called when I navigate as soon as I come on "MyPage.aspx"?

Cheers
Rais

推荐答案

找到了替代解决方案来解决此问题.

1)将ScriptManagerEnablePageMethods属性设置为 true .
Found Alternate solution to resolve this issue.

1) Set EnablePageMethods property of your ScriptManager to true.
<asp:scriptmanager id="ScriptManager1" runat="server" enablepagemethods="true" xmlns:asp="#unknown">
</asp:scriptmanager>



2)在隐藏代码(aspx.cs)中编写一个static方法,并向其中添加System.Web.Services.WebMethod属性.



2)Write a static method in code-behind(aspx.cs) and add System.Web.Services.WebMethod attribute to it.

[System.Web.Services.WebMethod]
public static void MyWCFMethod()
{
  //Implementation 
} 



3)然后按如下所示用Javascript调用WebMethod.



3) And then call your WebMethod in Javascript as below.

function BeforeNavigate()
{
     var isConfirm = confirm("Do you want to Navigate?");
     if (isConfirm ) 
     {
       PageMethods.MyWCFMethod();
       return false;
     }

}



希望这会有用.干杯-Rais



Hope this will be usefull. Cheers - Rais


这篇关于Asp.Net-WCF Javascript调用的ServiceReference问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆