I migrate from v11 to v12 and I want to replace:
var c = new CloudBlobClient(credentiels, delegatingHandler);
to
var c = new BlobServiceClient(uri, credentiels);
The problem is how to pass that the delegatingHandler
in v12?
v12 azure.Storage.Blobs class name is different from v11. v12 has no DelegatingHandler parameter in the constructor.
The DelegatingHandler can change the Proxy property of the HttpClientHandler.
ProxyInjectionHandler.cs
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace Hoge {
public class ProxyInjectionHandler: DelegatingHandler {
private readonly IWebProxy Proxy;
private bool FirstCall = true;
public ProxyInjectionHandler(IWebProxy proxy) {
this.Proxy = proxy;
}
protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
if (FirstCall) {
var handler = (HttpClientHandler) this.InnerHandler;
handler.Proxy = this.Proxy;
handler.UseProxy = true;
FirstCall = false;
}
return base.SendAsync(request, cancellationToken);
}
}
}
Pass this to the client's constructor.
var account = CloudStorageAccount.Parse (connectionString);
var client = new CloudBlobClient (account.BlobEndpoint, account.Credentials, new ProxyInjectionHandler (new WebProxy (new Uri (proxyUrl))));
var container = client.GetContainerReference ("...");
await container.CreateIfNotExistsAsync ();
REFERENCES:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.