we are trying to invoke azure cognitive services- translator api using azure function apps.We are getting the following error in the c# terminal:
No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
Our C# code for reference:
private const string key=" ";
private static readonly HttpClient client=new HttpClient
{
DefaultRequestHeaders={{"Ocp-Apim-Subscription-key",key}}
};
public static async Task Main()
{
while(true){
var text=Console.ReadLine();
var translatedText=await Translate(text,"en");
Console.WriteLine(translatedText);
}
}
public static async Task<string> Translate(string text,string language){
var encodedText=WebUtility.UrlEncode(text);
var uri="https://api.microsofttranslator.com/V2/Http.svc/Translate?" + $"to={language}&text={encodedText}";
var result=await client.GetStringAsync(uri);
return XElement.Parse(result).Value;
}
Also .csproj file code for reference:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<RootNamespace>transaltor_cognetive_service</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" >
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<PropertyGroup>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
</Project>