Answer by Gosen Gao · Feb 08 at 09:45 AM
Your code of Azure Function worked fine in my test. If there are no logs in the logstream, there may be something incorrect when registering the function to PlayFab. May I know how you register this function to PlayFab? Since this function requires no parameters, could you please use the function URL directly in the browser to see if you can get the correct result?
Hi, Thanks for quick response, indeed I had regsitered it wrong, a good nights sleep helps too :). I've just noticed I was using the wrong URL, I copied the one without the api/helloworld at the end of it from the VSCode output. All is working as it should :)
Answer by Iain Ross · Feb 07 at 07:35 PM
I have hacked it to just try and return a string value, I'm also not seeing any Logging coming via the azure portal logstream.
using System.Threading.Tasks; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using PlayFab.Samples; namespace PlayFabCS2AFSample.HelloWorld { public static class HelloWorld { [FunctionName("HelloWorld")] public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { await req.ReadAsStringAsync(); var message = "Hello!"; log.LogInformation("Hello"); //log.LogDebug($"HelloWorld: {new { input = inputValue} }"); log.LogDebug("HelloWorld"); return new { messageValue = message }; } } }
Answer by Iain Ross · Feb 07 at 07:38 PM
csproj is this
Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net6.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> <DefineConstants>NETCOREAPP3_1</DefineConstants> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" /> <PackageReference Include="PlayFabAllSDK" Version="1.108.220118" /> </ItemGroup> <ItemGroup> <None Update="host.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="local.settings.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None> </ItemGroup> </Project>
Answer by Iain Ross · Feb 07 at 07:41 PM
As you can probably tell I'm very new to PlayFab but it seems to do everything my next project is going to need.
I have removed/unregistered the actual function for now until next work on it.
Answer by Iain Ross · Feb 07 at 07:51 PM
This is the call function,
private void CallCSharpExecuteFunction() { PlayFabCloudScriptAPI.ExecuteFunction(new ExecuteFunctionRequest() { Entity = new PlayFab.CloudScriptModels.EntityKey() { Id = _entityKey.Id, //Get this from when you logged in, Type = _entityKey.Type, //Get this from when you logged in }, FunctionName = "imrhelloworld", //This should be the name of your Azure Function that you created. // FunctionParameter = new Dictionary<string, object>() { { "inputValue", "Iain" } }, //This is the data that you would want to pass into your function. GeneratePlayStreamEvent = false //Set this to true if you would like this call to show up in PlayStream }, (ExecuteFunctionResult result) => { if (result.FunctionResultTooLarge ?? false) { Debug.Log("This can happen if you exceed the limit that can be returned from an Azure Function, See PlayFab Limits Page for details."); return; } Debug.Log($"The {result.FunctionName} function took {result.ExecutionTimeMilliseconds} to complete"); Debug.Log($"Result: {result.FunctionResult.ToString()}"); }, (PlayFabError error) => { Debug.Log($"Opps Something went wrong: {error.GenerateErrorReport()}"); }); }