0

我在使用 WCF 服务中的异步模式和链接方法时遇到了一些问题。客户端异步调用WCF,则服务方法需要异步打开一个SOAP代理并调用一些方法。

问题是 Soap 服务的本质是顺序的,这意味着我需要一个结果,然后才能获得下一个结果并将其返回给调用 WCF 服务。我正在尝试使用异步模式,但在这里失败得很惨,因为顺序调用会成为其他异步调用的瓶颈,直到它完成。

有没有办法链接这些异步 SOAP 方法,以防止出现瓶颈?

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class DetailsService : IDetailService
{

    public DetailEntity GetDetails(DetailEntity entity)
    {

        TransactionUtilities.GetTransactionDetails(entity);

         // return modified entity with details
        return entity;

    }

}

public static class TransactionUtilities
{
    static SoapClient SoapProxy { get; set; }

    public static void GetTransactionDetails(DetailEntity entity)
    {
        IAsyncResult ar = SoapProxy.BeginExecuteTransaction(loginToken, new AsyncCallback(OnExecuteTransactionEnd), null);
        // will this block other async calls?
        ar.AsyncWaitHandle.WaitOne();
        string transactionId = SoapProxy.EndExecuteTransaction(ar);

        // another async call dependent on above transactionId
        IAsyncResult ar = SoapProxy.BeginGetTransactionResult(loginToken, processId, new AsyncCallback(OnTransactionResultEnd), null);
        ar.AsyncWaitHandle.WaitOne();
        Row[] TransactionResult = SoapProxy.EndGetTransactionResult(ar);

        // do work with result
    }

            // call back methods, just haning out doing nothing
    static void OnExecuteTransactionEnd(IAsyncResult result) { }
    static void OnTransactionResultEnd(IAsyncResult result) { }

}
4

0 回答 0