从另一个Web服务的成功功能中调用C#Web服务? [英] Calling a C# webservice from the Success function of another Webservice?

查看:47
本文介绍了从另一个Web服务的成功功能中调用C#Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单.您可以从另一个Web服务的成功"功能调用C#Web服务吗?我认为答案是否定的.

My question is simple. Can you call a C# webservice from the Success function of another webservice? I think that the answer is no.

我有一个登录Web服务,当用户尝试执行需要该用户登录的操作时,将调用该登录Web服务.然后,它将调用另一个Web服务,当操作完成时,它不会进入onSuccess函数.我以为它不能这样做?这是正确的吗?

I have a login webservice which is called when a user tries to do something that requires the user to be logged in. This then calls another webservice, when the action is complete it does not go into the onSuccess function. I am assuming that it is not able to do so? Is this correct?

示例代码,而不是实际代码.

Example code, not actual code.

webservice.login(onLoginSuccess)

function onLoginSuccess(){

    webservice.doSomething(onDoSomethingSuccess)

}

function onDoSomethingSuccess(){

    .... does not get here.

}

这是它的基本代码.

在客户端JavaScript调用上,登录Web服务成功.

On client JavaScript call, success of login webservice.

function onLoginSuccess(result){


    negotiateWithUser(true,
                      activeUser.id,
                      negotiation.dateID,
                      activeUser.showChat,
                      true);
}


function negotiateWithUser() {

    <code>

    if (justLoggedIn) updateDateData();

    <code>
}

 function updateDateData(){
     if (populate==false){

         populate=true;       
        WebService.Negotiations.DatesGet(activeUser.id,SucceededtoCallbackDateRefresh, ErrorHandler);          
     }
}

即使返回了数据且没有错误,也不会进入函数SucceededtoCallbackDateRefresh.

Does not go into the function SucceededtoCallbackDateRefresh even though data is returned and there are no errors.

我想我知道问题出在哪里,在contractWithUser函数中调用updateDateData,将执行控制权交还给contractWithUser函数,而不是进入SucceededtoCallbackDateRefresh成功函数,因为它是一个异步调用.我认为某种回调函数是必需的.

I think I know what the problem is, in the negotiateWithUser function the updateDateData is called, execution control is given back to the negotiateWithUser function instead of going into the SucceededtoCallbackDateRefresh success funtion, as it is an asynchronous call. I think some kind of callback function is required.

我通过在onLoginSuccess函数的setInterval()中调用updataDateData函数来解决此问题.

I have got round the problem by calling the updataDateData function in a setInterval() in the onLoginSuccess function instead.

 function onLoginSuccess(result){ 

      if (negotiate) {              
           timerInterval = setInterval("updateDateData()", 300);
      }

 }

有效.如果有人采用更优雅的方法,我将非常感兴趣.
谢谢.

It works. If someone has a more graceful approach, I would be very interested.
Thanks.

推荐答案

如何使用jQuery.ajax()?

How about to use jQuery.ajax()?

 function Func1() {
    $.ajax({
        url:'MyWebService.asmx/Func1',
        success:Func1Success,
        error: function () {
            alert('there was an error!');
        },
    });
    return false;
}
function Func1Success(output){
  $.ajax({
        url:'MyWebService.asmx/Func2',
        success:Func1SuccessToSuccess,
        error: function () {
            alert('there was an error!');
        },
    });
}
function Func1SuccessToSuccess() {
    return false;
}

这篇关于从另一个Web服务的成功功能中调用C#Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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