/// <summary> /// Invokes a method on a Dapr app. /// </summary> /// <param name="appId">The Dapr application id to invoke the method on.</param> /// <param name="methodName">The name of the method to invoke.</param> /// <param name="data">Byte array to pass to the method</param> /// <param name="httpOptions">Additional fields that may be needed if the receiving app is listening on HTTP.</param> /// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param> /// <returns>A <see cref="ValueTask{T}" /> that will return the value when the operation has completed.</returns> public abstract Task <InvocationResponse <byte[]> > InvokeMethodRawAsync( string appId, string methodName, byte[] data, HttpInvocationOptions httpOptions = default, CancellationToken cancellationToken = default);
/// <summary> /// Invokes a method on a Dapr app. /// </summary> /// <param name="appId">The Dapr application id to invoke the method on.</param> /// <param name="methodName">The name of the method to invoke.</param> /// <param name="data">Data to pass to the method</param> /// <param name="httpOptions">Additional fields that may be needed if the receiving app is listening on HTTP.</param> /// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param> /// <returns>A <see cref="Task{InvokeResponse}" /> that will return the value when the operation has completed.</returns> public abstract Task <InvocationResponse <TResponse> > InvokeMethodWithResponseAsync <TRequest, TResponse>( string appId, string methodName, TRequest data, HttpInvocationOptions httpOptions = default, CancellationToken cancellationToken = default);
private (Autogenerated.InvokeServiceRequest, CallOptions) MakeInvokeRequestAsync( string appId, string methodName, Any data, HttpInvocationOptions httpOptions, CancellationToken cancellationToken = default) { var protoHTTPExtension = new Autogenerated.HTTPExtension(); Metadata headers = null; string contentType; if (httpOptions != null) { protoHTTPExtension.Verb = ConvertHTTPVerb(httpOptions.Method); if (httpOptions.QueryString != null) { foreach (var(key, value) in httpOptions.QueryString) { protoHTTPExtension.Querystring.Add(key, value); } } if (httpOptions.Headers != null) { headers = new Metadata(); foreach (var(key, value) in httpOptions.Headers) { headers.Add(key, value); } } contentType = httpOptions.ContentType ?? Constants.ContentTypeApplicationJson; } else { protoHTTPExtension.Verb = Autogenerated.HTTPExtension.Types.Verb.Post; contentType = Constants.ContentTypeApplicationJson; } var invokeRequest = new Autogenerated.InvokeRequest() { Method = methodName, Data = data, ContentType = contentType, HttpExtension = protoHTTPExtension }; var request = new Autogenerated.InvokeServiceRequest() { Id = appId, Message = invokeRequest, }; var callOptions = new CallOptions(headers: headers ?? new Metadata(), cancellationToken: cancellationToken); // add token for dapr api token based authentication var daprApiToken = Environment.GetEnvironmentVariable("DAPR_API_TOKEN"); if (daprApiToken != null) { callOptions.Headers.Add("dapr-api-token", daprApiToken); } return(request, callOptions); }
/// <summary> /// Invokes a method on a Dapr app. /// </summary> /// <typeparam name="TResponse">The type of the object in the response.</typeparam> /// <param name="appId">The Dapr application id to invoke the method on.</param> /// <param name="methodName">The name of the method to invoke.</param> /// <param name="httpOptions">Additional fields that may be needed if the receiving app is listening on HTTP.</param> /// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param> /// <returns>A <see cref="ValueTask{T}" /> that will return the value when the operation has completed.</returns> public abstract ValueTask <TResponse> InvokeMethodAsync <TResponse>( string appId, string methodName, HttpInvocationOptions httpOptions = default, CancellationToken cancellationToken = default);
/// <summary> /// Invokes a method on a Dapr app. /// </summary> /// <typeparam name="TRequest">The type of data to send.</typeparam> /// <param name="appId">The Dapr application id to invoke the method on.</param> /// <param name="methodName">The name of the method to invoke.</param> /// <param name="data">Data to pass to the method</param> /// <param name="httpOptions">Additional fields that may be needed if the receiving app is listening on HTTP.</param> /// <param name="cancellationToken">A <see cref="CancellationToken" /> that can be used to cancel the operation.</param> /// <returns>A <see cref="Task{T}" /> that will return the value when the operation has completed.</returns> public abstract Task InvokeMethodAsync <TRequest>( string appId, string methodName, TRequest data, HttpInvocationOptions httpOptions = default, CancellationToken cancellationToken = default);