我需要连接到 Web 服务来执行交易。为此,我正在使用 class NetSuiteService:System.Web.Services.Protocols.SoapHttpClientProtocol。为了获得服务,我需要登录。我不想在每次需要执行交易时创建 Web 服务并登录。我有它的功能。
private static NetSuiteService Service { get; set; } = new NetSuiteService();
private static void isOnline()
{
if (Service.applicationInfo != null) return;
Service.CookieContainer = new CookieContainer();
Service.applicationInfo = new ApplicationInfo();
var passport = new Passport();
passport.account = "aaa";
passport.email = "bbb";
var role = new RecordRef();
passport.password = "999";
try
{
var status = Service.login(passport).status;
if (!status.isSuccess)
{
Log.ErrorFormat("can't login to NetSuite - {0}", status.statusDetail);
Service.applicationInfo = null;
}
}
catch (Exception ex)
{
Log.Error("NetSuite login err", ex);
}
}
但有时我的连接超时,我需要重新连接。在这种情况下,我在执行交易时遇到异常。
是否有可能以某种方式知道我的会话在进行交易之前是否超时?