使用Gremlin.Net的Azure Cosmos DB - 提交查询时出错

时间:2018-04-09 17:58:27

标签: azure azure-cosmosdb

使用Gremlin.net(V 3.3.2)中的示例代码我正在尝试连接到Cosmos DB。当task.Wait()执行时,我收到以下错误:

“WebSocketException:当预期状态代码为'101'时,服务器返回状态代码'200'”

为什么会失败的任何想法?相同的代码适用于亚马逊海王星。

var gremlinServer = new GremlinServer(hostname, port, enableSsl: true,username: "/dbs/" + database + "/colls/" + collection,password: authKey);

using (var gremlinClient = new GremlinClient(gremlinServer, new GraphSON2Reader(), new GraphSON2Writer(), GremlinClient.GraphSON2MimeType))

var task = gremlinClient.SubmitAsync<dynamic>(query.Value);
task.Wait();

1 个答案:

答案 0 :(得分:2)

正如汤姆所说,发表答案

创建客户端时,主机名应与documentdb不同,类似

<强> sample.gremlin.cosmosdb.azure.com

代码看起来像

 private static GremlinServer GetGremlinServer(IConfigurationRoot builder)
 {
            var hostname = builder["cosmosDBConnection:gremlinEndpoint"];
            var port = builder.GetValue<int>("cosmosDBConnection:gremlinPort", 443);
            var authKey = builder["cosmosDBConnection:authKey"];
            var databaseId = builder["cosmosDBConnection:databaseId"];
            var graphId = builder["cosmosDBConnection:graphId"];

            var gremlinServer = new GremlinServer(hostname, port, enableSsl: true, username: $"/dbs/{databaseId}/colls/{graphId}", password: authKey);
            return gremlinServer;
 }