首页 > 解决方案 > Dapr 资源绑定来自外部服务的 HTTP GET

问题描述

我试图创建一个 Dapr 组件,如下所示:

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: nominatim
  namespace: default
spec:
  type: bindings.http
  version: v1
  metadata:
  - name: url
    value: https://nominatim.openstreetmap.org
  - name: method
    value: GET
  - name: UserAgent
    value: Other

然后在我的服务中,我像这样调用了这个 binging:

var getAddressUrl = $"{UriString}/reverse?format=jsonv2&lat={latitude}&lon={longitude}&zoom=18&addressdetails=1";

var invokeBindingAsync = _daprClient.InvokeBindingAsync<object, AddressLocationDto>(
    DaprComponentsSettings.HttpNominatim,
    DaprComponentsSettings.CreateBindingOperation,
    null,
    new Dictionary<string, string>
    {
        ["url"] = getAddressUrl
    });
var address = await invokeBindingAsync;
return address;

不幸的是,我收到以下错误:

Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: Connection refused (127.0.0.1:50001) SocketException: Connection refused", DebugException="System.Net.Http.HttpRequestException: Connection refused (127.0.0.1:50001)
 ---> System.Net.Sockets.SocketException (111): Connection refused
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|283_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.DefaultConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
   at System.Net.Http.ConnectHelper.ConnectAsync(Func`3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.ConnectHelper.ConnectAsync(Func`3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttp2ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)")

我不知道如何像这样调用 HTTP get。请帮忙。

标签: c#asp.net-coredapr

解决方案


推荐阅读