1

我尝试通过公共交通请求/响应实现异步服务操作 ( http://msdn.microsoft.com/en-us/library/ms731177.aspx )。

[ServiceContract]
public interface IService1
{
    [OperationContractAttribute(AsyncPattern = true)]
    IAsyncResult BeginMyOperation(string data, AsyncCallback callback, object asyncState);

    string EndMyOperation(IAsyncResult result);
}

public class Service1 : IService1
{
    private string _answer;

    public IAsyncResult BeginMyOperation(string data, AsyncCallback callback, object asyncState)
    {
        return Bus.Instance.BeginPublishRequest(
            new MyRequestMessage { Data = data }, callback, asyncState, cfg =>
                {
                    cfg.Handle<MyResponseMessage>(c => _answer = c.Answer);
                    cfg.SetTimeout(5.Seconds());
                });
    }

    public string EndMyOperation(IAsyncResult result)
    {
        Bus.Instance.EndPublishRequest<MyResponseMessage>(result);
        return _answer;
    }
}

但 EndPublishRequest 抛出异常“参数不是 IRequest”。难道我做错了什么?

4

1 回答 1

0

是的,如果您查看签名,异常消息需要更好一些:

public static bool EndPublishRequest<TRequest>(this IServiceBus bus, IAsyncResult asyncResult)

很明显,请求消息类型是此处所需的类型 arg。

于 2013-07-30T15:32:05.663 回答