Allow HttpRequestMessage to accept relative URLs in service invocation
See original GitHub issueBackground
The Dapr SDK allows invoking service methods using an HttpRequestMessage
parameter. However, this overload requires a fully qualified URL to the Dapr sidecar. Otherwise, an InvalidOperationException
is thrown.
HttpRequestMessage httpRequest = new(input.HttpMethod, input.MethodName);
return await this.daprClient.InvokeMethodAsync<object?>(httpRequest);
Here is the exception:
System.InvalidOperationException
HResult=0x80131509
Message=An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set.
Source=System.Net.Http
StackTrace:
at System.Net.Http.HttpClient.PrepareRequestMessage(HttpRequestMessage request)
at System.Net.Http.HttpClient.CheckRequestBeforeSend(HttpRequestMessage request)
at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Dapr.Client.DaprClientGrpc.<InvokeMethodWithResponseAsync>d__27.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Dapr.Client.DaprClientGrpc.<InvokeMethodAsync>d__29`1.MoveNext()
...
[Call Stack Truncated]
Generally speaking, code that already has a fully configured DaprClient
should not need to provide redundant endpoint information for the Dapr sidecar. In many cases, it may not be practical for code to know what it is - for example, when getting the DaprClient
from dependency injection, in which case the configuration comes from the config system.
Proposal
Remove the requirement in InvokeMethodAsync
for the HttpRequestMessage
parameter to use a fully qualified URL. The DaprClient
implementation can construct the real URL itself using its own internally tracked endpoint. This will make this particular method much easier to use.
Issue Analytics
- State:
- Created a year ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
Thanks for the feedback @cgillum
Irrespective of this actual proposal … I’d recommend using https://github.com/dapr/dotnet-sdk/blob/master/src/Dapr.Client/DaprClient.cs#L75 to create an
HttpClient
and just using the standard .NET APIs. There’s a wealth of existing libraries and knowledge for how to useHttpClient
.This is the case, if you omit the endpoint argument then the SDK will do it for you.
Alright cool 😆 - feel free to reach out if you want to spend some time talking in details.