在ServiceStack中,您可以创建一个JsonServiceClient并监听上传进度,如下所示:
var client = new JsonServiceClient("http://api.example.org");
client.OnUploadProgress += (done, total) => {
};
但是,将其与缓存结合使用时:
var client = new JsonServiceClient("http://api.example.org").WithCache();
这不起作用,因为 WithCache()
返回一个 IServiceClient
,它没有实现 OnUploadProgress
。
有什么方法可以在使用 WithCache()
的同时使用 OnUploadProgress
吗?
最佳答案
WithCache()
扩展方法返回 CachedServiceClient
的新实例,该实例增强了 JsonServiceClient
实例来管理本地 HTTP 缓存层围绕 GET 请求。
OnUploadProgress
是一个回调,用于通知文件上传。
您可以根据需要配置 JsonServiceClient
:
var client = new JsonServiceClient("http://api.example.org") {
OnUploadProgress = (done, total) => ..
};
然后根据修改后的实例创建增强型缓存客户端,例如:
var cacheClient = client.WithCache();
关于c# - JsonServiceClient的OnUploadProgress可以和.WithCache()结合使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44799355/