首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >多次调用识别接口的时候,经常会在第二次调用的时候卡住?

多次调用识别接口的时候,经常会在第二次调用的时候卡住?

提问于 2020-03-16 11:23:28
回答 0关注 0查看 382

本地调试,第一次调用接口可以识别,后续的调用会卡在BizLicenseOCRResponse resp = await client.BizLicenseOCR(req);这里,没有返回,也没有报错。需要重新启动后台接口应用程序和前端web应用程序才能成功。代码如下

using System;

using System.Collections.Generic;

using System.Configuration;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Collections;

using TencentCloud.Common;

using TencentCloud.Common.Profile;

using TencentCloud.Ocr.V20181119;

using TencentCloud.Ocr.V20181119.Models;

using MZSP.API.BLL;

using MZSP.DAL;

using MZSP.Entity;

namespace MZSP.View.BLL.Controls

{

class OCRLicenseControl

{

private async Task<BizLicenseOCRResponse> GetAddress(string pLicenseImgUrl)

{

Credential cred = new Credential

{

SecretId = ConfigurationManager.AppSettings["spSecId"].ToString(),

SecretKey = ConfigurationManager.AppSettings["spSecKey"].ToString()

};

ClientProfile clientProfile = new ClientProfile();

HttpProfile httpProfile = new HttpProfile();

httpProfile.Endpoint = ("ocr.tencentcloudapi.com");

clientProfile.HttpProfile = httpProfile;

OcrClient client = new OcrClient(cred, "ap-guangzhou", clientProfile);

BizLicenseOCRRequest req = new BizLicenseOCRRequest();

string strParams = "{\"ImageUrl\":\"" + pLicenseImgUrl + "\"}";

req = BizLicenseOCRRequest.FromJsonString<BizLicenseOCRRequest>(strParams);

BizLicenseOCRResponse resp = await client.BizLicenseOCR(req);

return resp;

}

private void GetPrivonceCity(string RegNum, ref Tschools school)

{

school.FProvince = TareaBLL.GetInstance().GetOneByID(RegNum.Substring(2, 2)).FAreaName;

school.FCity = TareaBLL.GetInstance().GetOneByID(RegNum.Substring(2, 4)).FAreaName;

school.FCounty = TareaBLL.GetInstance().GetOneByID(RegNum.Substring(2, 6)).FAreaName;

}

public object GetShoolInfoFromLicense(string pLicenseImgUrl)

{

Hashtable hs = new Hashtable();

hs["msg"] = "营业执照识别失败";

hs["flag"] = false;

BizLicenseOCRResponse result = null;

try

{

var t = Task.Run(() =>

{

// 同步方式调用,会卡住直到请求返回

result = GetAddress(pLicenseImgUrl).ConfigureAwait(false).GetAwaiter().GetResult();

});

// 同步等待,会卡住直到线程返回

t.Wait();

Tschools school = new Tschools();

GetPrivonceCity(result.RegNum, ref school);

school.FSchoolName = result.Name;

school.FOwner = result.Person;

school.FAddress = result.Address;

hs["SchoolInfoFromLicense"] = school;

hs["msg"] = "营业执照识别成功";

hs["flag"] = true;

return hs;

}

catch (Exception e)

{

FuncUtility.Utils.WriteErrLogToTxt("营业执照识别失败", e);

hs["msg"] = "营业执照识别失败";

hs["flag"] = false;

return hs;

}

}

}

}

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档