部署在Azure上后,我无法从MS Bot(v4)C#进行本地API调用。使用模拟器进行本地测试时,Premise API调用可以正常工作。
按照Microsoft支持团队的建议,我已经尝试过使用Direct Line通道进行网络聊天,但无济于事。
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
HttpWebRequest webRequest = HttpWebRequest.CreateHttp(updatedURL);
webRequest.Method = currentStep.StepsServiceCall.Method;
webRequest.ContentType = "application/json";
webRequest.KeepAlive = true;
if (!String.IsNullOrEmpty(currentStep.StepsServiceCall.Headers))
{
string updatedJson = currentStep.InjectPropertyValuesJson(currentStep.StepsServiceCall.Headers, properties);
webRequest.ContentLength = updatedJson.Length;
using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))
{
streamWriter.Write(updatedJson);
streamWriter.Flush();
streamWriter.Close();
}
}
using (HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse)
{
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string content = reader.ReadToEnd();
return await currentStep.ProcessResponseText(context, cancellationToken, content);
}
从Azure App Service日志获取以下错误。
Microsoft.Bot.Builder.Integration.AspNet.Core.BotFrameworkHttpAdapter:捕获到异常:发送请求时发生错误。错误12029,调用WINHTTP_CALLBACK_STATUS_REQUEST_ERROR,“无法建立与服务器的连接”。
答案 0 :(得分:1)
对于我来说,该错误消息看起来相当简单,您的Azure App Service无法访问托管内部部署API的URL。假设托管API的服务器响应ICMP数据包(ping),我将尝试以下操作:
ping <url-here>
来完成。App Service > Development Tools > Advanced tools > Go