c# - 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。请帮忙。
解决方案
推荐阅读
- reactjs - 为什么我在使用钩子时不能使用 camelCase 命名反应箭头功能组件?
- c - 如何转换不安全指针
迅速串起来 - python - 在表服务查询中使用用户定义的列表
- c# - 在 UWP 应用上打开 pdf 文件所需的代码问题
- excel - 如何在循环中使用 MATCH?
- angular - 更改时输入数字失去焦点
- automated-tests - 有没有办法在不使用相应插件“testcafe-browser-provider-saucelabs”的情况下将 testcafe 脚本运行到 Sauce lab?
- docker - Argo工件通过无法保存输出
- grafana - 将 MIB 变量标签连接到 Prometheus 中其他两个 MIB 变量的另一个查询结果
- mulesoft - 需要识别骡子经营者