Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WCF异步模式和masstransit请求/响应_Wcf_Masstransit - Fatal编程技术网

WCF异步模式和masstransit请求/响应

WCF异步模式和masstransit请求/响应,wcf,masstransit,Wcf,Masstransit,我尝试使用masstransit请求/响应实现异步服务操作() [ServiceContract] public interface IService1 { [OperationContractAttribute(AsyncPattern = true)] IAsyncResult BeginMyOperation(string data, AsyncCallback callback, object asyncState); string EndMyOperation

我尝试使用masstransit请求/响应实现异步服务操作()

[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;
    }
}
[服务合同]
公共接口IService1
{
[OperationContractAttribute(AsyncPattern=true)]
IAsyncResult BeginMyOperation(字符串数据、异步回调、对象异步状态);
字符串EndMyOperation(IAsyncResult结果);
}
公共类服务1:IService1
{
私人字符串(u)应答;;
公共IAsyncResult BeginMyOperation(字符串数据、异步回调、对象异步状态)
{
return Bus.Instance.BeginPublishRequest(
新建MyRequestMessage{Data=Data},回调,异步状态,cfg=>
{
句柄(c=>_-answer=c.answer);
SetTimeout(5.Seconds());
});
}
公共字符串EndMyOperation(IAsyncResult结果)
{
Bus.Instance.EndPublishRequest(结果);
返回答案;
}
}

但是EndPublishRequest抛出了一个异常“该参数不是IRequest”。我做错了什么吗?

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

public static bool EndPublishRequest<TRequest>(this IServiceBus bus, IAsyncResult asyncResult)
公共静态bool EndPublishRequest(此IServiceBus总线,IAsyncResult asyncResult)
显然,请求消息类型是此处所需的类型arg