首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >用web方式调用营业执照识别API,经常是第一次可以识别,后面再次调用,就需要回收IIS应用程序池?

用web方式调用营业执照识别API,经常是第一次可以识别,后面再次调用,就需要回收IIS应用程序池?

提问于 2020-03-24 17:18:23
回答 0关注 0查看 228

我是参照这篇文章 https://cloud.tencent.com/developer/article/1395819

来解决WEB异步调用返回数据的问题,但问题是经常第一次可以识别,后面再次调用,就需要回收IIS应用程序池。否则就卡在 BizLicenseOCRResponse resp = await client.BizLicenseOCR(req);这一行代码,没有异常也没有返回。这是为什么呢?

================================================================================

代码如下:

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;

}

public object GetShoolInfoFromLicense(string pLicenseImgUrl)

{

Hashtable hs = new Hashtable();

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;

}

catch (Exception e)

{

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

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

hs["flag"] = false;

}

return hs;

}

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;

}

}

}

回答

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

相似问题

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