【问题标题】:API Gateway Websocket @Connection endpoint not found未找到 API Gateway Websocket @Connection 端点
【发布时间】:2019-06-11 02:15:50
【问题描述】:

我正在尝试从 $connect 路由向潜在连接的客户端发送套接字消息。我成功地从 dynamodb 检索到连接 ID。每当我尝试发送任何内容时,都会收到错误消息:

No method found matching route %40connections/aM50DdTXCYcCGEA%3D for http method POST

我用来发送的代码:

Amazon.Runtime.AWSCredentials cd = new Amazon.Runtime.BasicAWSCredentials("*******", "******");

var domainName = request.RequestContext.DomainName;
var endpoint = $"https://{domainName}/{stage}";
context.Logger.LogLine($"API Gateway management endpoint: {endpoint}");

 apiClient = new AmazonApiGatewayManagementApiClient(cd,
                new AmazonApiGatewayManagementApiConfig
                {
                    ServiceURL = endpoint,
                    RegionEndpoint = Amazon.RegionEndpoint.USEast2
                });
Message testMessage = new Message()
            {
                AppId = "TestApp",
                CommandData = "Testing"
            };


MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(testMessage)));

PostToConnectionResponse response = await apiClient.PostToConnectionAsync(new PostToConnectionRequest()
                    {
                        ConnectionId = Uri.EscapeUriString(existing.ConnectionId),
                        Data = stream
                    });

我似乎找不到任何表明 POST 端点为什么不工作的东西(我在 nodejs 中有一个工作示例,但我们需要在 .Net 中完成)。如果有人对我如何找到问题所在有任何建议,将不胜感激。

我已确认端点与部署的 WebSocket API 网关 url 匹配。

Visual Studio 2017

.Net Core 2.1

AWSSDK.ApiGatewayManagementApi 3.3.100.23

谢谢!

【问题讨论】:

    标签: c# .net aws-sdk-net


    【解决方案1】:

    我做了更多相同的代码并且它有效

            AmazonApiGatewayManagementApiClient client = new AmazonApiGatewayManagementApiClient(new AmazonApiGatewayManagementApiConfig() {
                ServiceURL = "https://" + request.RequestContext.DomainName + "/" + request.RequestContext.Stage
            });
    
            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(document)));
            PostToConnectionRequest postRequest = new PostToConnectionRequest()
            {
                ConnectionId = request.RequestContext.ConnectionId,
                Data = stream
            };
    
            var result = client.PostToConnectionAsync(postRequest);
            result.Wait();
    

    【讨论】:

    • 除了代码之外,您的回答提供的信息很少。分解为什么要做这些事情
    【解决方案2】:

    我最终删除了所有 IAM 角色并重新创建了它们。我猜有些东西配置错误,或者如果 IAM 使用任何类型的缓存系统,它可能被锁定到旧版本。它现在正在工作。很抱歉延迟在这里发布我的发现!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-25
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      • 2021-06-19
      • 2019-09-11
      相关资源
      最近更新 更多