クラス ライブラリに Web 参照 (WSDL) を追加し、タイマーでトリガーされる C# Azure 関数( Azure 関数の詳細を参照) でその dll を参照しました。クラス ライブラリには、Web サービス (Web サービス ラッパーの一種) からメソッドを呼び出すクラス EmployeeService があります。コンソール アプリケーションからクラス lib メソッド (GetEmployees) を呼び出すと、Web サービスに対して認証され、結果が返されますが、同じコードと資格情報に対して azure 関数を実行すると、401 が返されます。ここで何が間違っているのかわかりません。
#r "MyConsult.Service.dll"
#r "Newtonsoft.Json.dll"
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using Newtonsoft.Json;
using System.Net;
using MyConsult.Service.Service;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
try
{
EmployeeService _empService = new EmployeeService();
var emps = _empService.GetEmployees();
int count = emps.Where(x => !string.IsNullOrEmpty(x.Email)).Select(x => x.Email).Distinct().Count();
log.Info($"employee count : {count}");
}
catch (Exception ex)
{
log.Info($"Exception Message: {ex.Message}");
log.Info($"Exception Stack Trace: { ex.StackTrace}");
}
}