Could not bootstrap with CCCP : Couchbase memcached bucket exception - c#

I'm using the latest version of CouchbaseNetClient NuGet package 2.7.4 to connect Couchbase 4.6.3 enterprise version(running on docker in my laptop).
C# Code :
var config = new ClientConfiguration
{
// assign one or more Couchbase Server URIs available for bootstrap
Servers = new List<Uri>
{
new Uri("http://192.168.99.100:8091/")
},
BucketConfigs = new Dictionary<string, BucketConfiguration> {
{"memcachetest", new BucketConfiguration {
PoolConfiguration = new PoolConfiguration {
MaxSize = 6,
MinSize = 4,
SendTimeout = 12000
},
Port = 8091,
DefaultOperationLifespan = 123,
Password = "",
Username = "",
BucketName = "memcachetest"
}}},
UseSsl = false,
};
ClusterHelper.Initialize(config);
This code works fine for the normal bucket(sample bucket below) but I'm unable to connect to Memcached(memcachetest) bucket.
Following line throws all sorts of exception while opening the bucket.
private readonly IBucket _bucket = ClusterHelper.GetBucket("memcachetest", "");
I have tried with/without passwords. It's all over my head now from the last 2 days! Any help appriciated!!

Memcached buckets don't support CCCP. The client will first try CCCP and then move to HTTP Streaming when CCCP fails - this gets logged and probably what you stumbled onto. Since it's an AggregateException, it appears that there may be other reasons why its failing - you'll have to look into each exception for the reason. Note you can skip CCCP for Memcached buckets by setting ConfigurationProviders to HttpStreaming:
ClientConfiguration.ConfigurationProviders = ServerConfigurationProviders.HttpStreaming;

Related

How to avoid having to pass a "root certificate" to the client when developing a gRpc service between 2 desktop applications

I've 2 desktop applications in .Net that communicate between each other. Up until now they were using WCF but we are moving toward .Net 6 so we have to update them.
They run on a local network without internet connection but we require the user to enter a password, just to avoid the technician to connect to the wrong server and misconfigure something.
Our server is a WPF application, so we will not be hosting the service inside an Asp.Net server.
Currently, I've made and retrieved this code:
[Test]
public void CustomTest()
{
string rootCert = File.ReadAllText(TestCredentials.ClientCertAuthorityPath);
keyCertPair = new KeyCertificatePair(
File.ReadAllText(TestCredentials.ServerCertChainPath),
File.ReadAllText(TestCredentials.ServerPrivateKeyPath));
VerifyPeerCallback verifyFunc = context =>
{
return true;
};
var serverCredentials = new SslServerCredentials(new[] { keyCertPair }, rootCert, SslClientCertificateRequestType.DontRequest);
var clientCredentials = new SslCredentials(rootCert, null, verifyFunc);
// Disable SO_REUSEPORT to prevent https://github.com/grpc/grpc/issues/10755
server = new Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) })
{
Ports = { { Host, ServerPort.PickUnused, serverCredentials } }
};
sslCredentialsTestServiceImpl = new SslCredentialsTestServiceImpl();
server.Services.AddCodeFirst<ITestService>(sslCredentialsTestServiceImpl, default, Console.Out);
server.Start();
var options = new List<ChannelOption>
{
new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride)
};
channel = new Channel(Host, server.Ports.Single().BoundPort, clientCredentials, options);
client = channel.CreateGrpcService<ITestService>();
CallContext callContext = default;
var call = client.UnaryCall(new SimpleRequest(), callContext);
Assert.AreEqual(false, sslCredentialsTestServiceImpl.WasPeerAuthenticated);
}
It works. But:
I don't understand why we have to provide the root certificate to the client? Shouldn't this check the windows certificate directory for the available certificate?
Same question for the server. I understand why we have to provide the certificate, but not why we need to provide the CA certificate?
Also, is there an (unsecure) way to use credentials but no SSL? I know that make no sense in a security standpoint, but in our case, it's just to avoid dum errors, the user will either be on the same computer with the 2 software, either in the same room

Retrive Wordoffsets for interim results

I am using the following config to retrieve results from the speech api:
StreamingConfig = new StreamingRecognitionConfig
{
Config = new RecognitionConfig
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
SampleRateHertz = 8000,
LanguageCode = languageCode,
EnableWordTimeOffsets = true
},
InterimResults = true
}
When retriving a result, the WordTimeOffsets should be included in the WordInfos of the property Alternatives.
Unfortunately, I am only getting WordInfos for results where IsFinal = true.
When retrieving interim results the array of words is empty although a transcript is there.
I have installed 1.1.0-beta02 from nuget and setup a .NET Core project.
I have read through the documentation and through some articles in the internet but found no hint that the wordinfos are only filled for final results.
Please let me know if you need some additional information.

Azure Storage Emulator - Configuring CORS dynamically throws Server Authentication error

I'm using Microsoft.WindowsAzure.Storage C# library in .Net Core 2.0.
Using this library I'm trying to configure CORS dynamically in Azure Storage Emulator but getting error:
"Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature".
public async void ConfigureCors() {
ServiceProperties serviceProperties = await this.blobClient.GetServicePropertiesAsync();
serviceProperties.Cors = new CorsProperties();
serviceProperties.Cors.CorsRules.Clear();
serviceProperties.Cors.CorsRules.Add(new CorsRule() {
AllowedHeaders = allowedCorsHeaders,
ExposedHeaders = allowedCorsExposedHeaders,
AllowedOrigins = allowedCorsOrigin,
AllowedMethods = allowedCorsMethods,
MaxAgeInSeconds = allowedCorsAgeInSeconds
});
await blobClient.SetServicePropertiesAsync(serviceProperties);
}
I'm able to generate SAS key for upload files on local server directly, but is not able to configure CORS dynamically so that I can access storage via C# code.
Strange thing to note is that the above code is working perfectly fine when using Azure Storage Cloud but local emulator is throwing this error.
Version info:
WindowsAzure.Storage version is 8.4.0
Windows Azure Storage Emulator version 5.2.0.0
Azure storage explorer version is 0.9.01
Credentials used for connection:
AccountName=devstoreaccount1;
AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuF‌​q2UVErCz4I6tq/K1SZFP‌​TOtr/KBHBeksoGMGw==;
According to your description, I have created a test demo on my side. It works well.
I guess the reason why you get the Server failed to authenticate the request error is the wrong azure storage package version and storage emulator version.
I suggest you could update the storage version to 8.4.0 and storage emulator version to 5.2 firstly and try again.
More details about my test demo, you could refer to below codes:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
ServiceProperties serviceProperties = blobClient.GetServicePropertiesAsync().Result;
serviceProperties.Cors = new CorsProperties();
serviceProperties.Cors.CorsRules.Clear();
serviceProperties.Cors.CorsRules.Add(new CorsRule()
{
AllowedHeaders = new List<string>() { "*" },
ExposedHeaders = new List<string>() { "*" },
AllowedOrigins = new List<string>() { "*" },
AllowedMethods = CorsHttpMethods.Put | CorsHttpMethods.Get | CorsHttpMethods.Head | CorsHttpMethods.Post,
MaxAgeInSeconds = 1800
});
var re = blobClient.SetServicePropertiesAsync(serviceProperties);
Result:

Authenticate User on MongoDB with .NET Driver 2.4

The following code works as it should do, if the server is running and if the usename and password are correct. However, if i give a wrong username or password, it does not give me feedback, but only runs into a timeout when calling the Count method.
MongoClientSettings setts = new MongoClientSettings()
{
Server = new MongoServerAddress("127.0.0.1", 27017),
Credentials = new MongoCredential[] { MongoCredential.CreateCredential("TestDatabase", "username", "password") }
};
this.client = new MongoClient(setts);
this.client.Cluster.DescriptionChanged += this.ClusterDescriptionChanged;
var database = this.client.GetDatabase("TestDatabase");
var collection = database.GetCollection<BsonDocument>("SimpleCollection");
var count = collection.Count(MongoDB.Driver.FilterDefinition<BsonDocument>.Empty);
How do i get error messages from the driver and how can i check if it's the connection, the user or the password that does not fit?
PS: The driver API has changed a lot since 2.0 in Jan.2016, which means that most webtutorials and posts on this site no longer work for the current version.
Once you get the client, you can check if the connection is successful
var server = client.GetServer();
server.Ping();
Also it is always a good idea to enclose your code in a try catch with timeout exception because that is expected.
for more info on this you can refer MongoDB C# Driver check Authentication status & Role

Error while uploading the image to Azure Blob from a cordova application

I am trying to upload a blob from Cordova Application and I am getting 404. However, the SAS URL is valid and working fine with a C# Application.
Please find the code below:
var uriWithAccess = URL;
var xhr = new XMLHttpRequest();
xhr.onerror = fail;
xhr.onloadend = uploadCompleted;
xhr.open("POST", uriWithAccess);
xhr.setRequestHeader('x-ms-blob-type', 'BlockBlob');
xhr.setRequestHeader('x-ms-blob-content-type','image/jpeg');
xhr.send(requestData);
Any help will be appreciated. I tried with $.ajax as well but it's also giving 404 error.
PS: The code was working perfectly fine but from last few days it started causing the issue.
Thanks,
Mohit Chhabra
Have you configured CORS ? maybe the js request is failing because execution domain is not allowed in azure storage.
<Cors>
<CorsRule>
<AllowedOrigins>http://www.contoso.com, http://www.fabrikam.com</AllowedOrigins>
<AllowedMethods>PUT,GET</AllowedMethods>
<AllowedHeaders>x-ms-meta-data*,x-ms-meta-target*,x-ms-meta-abc</AllowedHeaders>
<ExposedHeaders>x-ms-meta-*</ExposedHeaders>
<MaxAgeInSeconds>200</MaxAgeInSeconds>
</CorsRule>
<Cors>
To set that configuration you can use azure Storage REST API, or more easily you can run a short C# program like this:
private static void InitializeCors()
{
// CORS should be enabled once at service startup
// Given a BlobClient, download the current Service Properties
ServiceProperties blobServiceProperties = BlobClient.GetServiceProperties();
ServiceProperties tableServiceProperties = TableClient.GetServiceProperties();
// Enable and Configure CORS
ConfigureCors(blobServiceProperties);
ConfigureCors(tableServiceProperties);
// Commit the CORS changes into the Service Properties
BlobClient.SetServiceProperties(blobServiceProperties);
TableClient.SetServiceProperties(tableServiceProperties);
}
private static void ConfigureCors(ServiceProperties serviceProperties)
{
serviceProperties.Cors = new CorsProperties();
serviceProperties.Cors.CorsRules.Add(new CorsRule()
{
AllowedHeaders = new List<string>() { "*" },
AllowedMethods = CorsHttpMethods.Put | CorsHttpMethods.Get | CorsHttpMethods.Head | CorsHttpMethods.Post,
AllowedOrigins = new List<string>() { "*" },
ExposedHeaders = new List<string>() { "*" },
MaxAgeInSeconds = 1800 // 30 minutes
});
}
I'm not sure about what host you should use to enable access to a mobile application, but at first you should try with all host.
Access-Control-Allow-Origin: *
AllowedOrigins = new List<string>() { "*" },
You can follow a detailed guide here:
Windows Azure Storage: Introducing CORS

Categories

Resources