async Task <MethodResult> InvokeMethodAsync(DirectMethodRequest directMethodRequest) { Events.ReceivedMethodCall(directMethodRequest, this.identity); IEdgeHub edgeHub = await this.edgeHubGetter; DirectMethodResponse directMethodResponse = await edgeHub.InvokeMethodAsync(this.identity.Id, directMethodRequest); Events.ReceivedMethodCallResponse(directMethodRequest, this.identity); MethodResult methodResult = GetMethodResult(directMethodResponse); return(methodResult); }
async Task <IActionResult> InvokeMethodAsync(DirectMethodRequest directMethodRequest) { Events.ReceivedMethodCall(directMethodRequest, this.identity); IEdgeHub edgeHub = await this.edgeHubGetter; DirectMethodResponse directMethodResponse = await edgeHub.InvokeMethodAsync(this.identity.Id, directMethodRequest); Events.ReceivedMethodCallResponse(directMethodRequest, this.identity); var methodResult = new MethodResult { Status = directMethodResponse.Status, Payload = GetRawJson(directMethodResponse.Data) }; return(this.Json(methodResult)); }
async Task <IActionResult> InvokeMethodAsync(DirectMethodRequest directMethodRequest) { Events.ReceivedMethodCall(directMethodRequest, this.identity); IEdgeHub edgeHub = await this.edgeHubGetter; DirectMethodResponse directMethodResponse = await edgeHub.InvokeMethodAsync(this.identity.Id, directMethodRequest); Events.ReceivedMethodCallResponse(directMethodRequest, this.identity); MethodResult methodResult = GetMethodResult(directMethodResponse); HttpResponse response = this.Request?.HttpContext?.Response; if (response != null) { response.ContentLength = GetContentLength(methodResult); } return(this.StatusCode((int)directMethodResponse.HttpStatusCode, methodResult)); }
async Task <MethodResult> InvokeMethodAsync(DirectMethodRequest directMethodRequest) { Events.ReceivedMethodCall(directMethodRequest); IEdgeHub edgeHub = await this.edgeHubGetter; MethodResult methodResult; string currentEdgeDeviceId = edgeHub.GetEdgeDeviceId(); if (this.TryGetActorId(out string actorDeviceId, out string actorModuleId)) { string actorId = $"{actorDeviceId}/{actorModuleId}"; if (actorDeviceId == currentEdgeDeviceId) { IHttpRequestAuthenticator authenticator = await this.authenticatorGetter; HttpAuthResult authResult = await authenticator.AuthenticateAsync(actorDeviceId, Option.Some(actorModuleId), this.HttpContext); if (authResult.Authenticated) { using (Metrics.TimeDirectMethod(actorDeviceId, directMethodRequest.Id)) { DirectMethodResponse directMethodResponse = await edgeHub.InvokeMethodAsync(actorId, directMethodRequest); Events.ReceivedMethodCallResponse(directMethodRequest, actorId); methodResult = GetMethodResult(directMethodResponse); } } else { methodResult = new MethodErrorResult(HttpStatusCode.Unauthorized, authResult.ErrorMessage); } } else { methodResult = new MethodErrorResult(HttpStatusCode.Unauthorized, "Only modules on the same device can invoke DirectMethods"); } } else { methodResult = new MethodErrorResult(HttpStatusCode.BadRequest, $"Invalid header value for {Constants.ServiceApiIdHeaderKey}"); } return(methodResult); }