2017-08-08 75 views
1

我需要連接到Web服務來執行事務。爲此我使用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); 
       } 

     } 

但是有時候我的連接被時間掉了,我需要重新連接。在這種情況下,我在執行交易時有例外。

是否有可能以某種方式知道我的會話在進行交易之前是否超時?

回答

0

下面的代碼創建登錄護照,您可以添加到您的服務

_service = new NetSuiteService(); 

Passport passport = new Passport(); 
passport.account = _custSettings["login.acct"]; 
passport.email = _custSettings["login.email"]; 
passport.password = _custSettings["login.password"]; 
RecordRef role = new RecordRef(); 
role.internalId = _custSettings["login.roleId"]; 
passport.role = role; 

_service.passport = passport; 

你只需要設置這個曾經,現在可以讓你所有的週三API調用,沒有超時。因此,不使用Service.login()方法,護照將自動與每個API調用一起使用。

我正在從配置文件中讀取登錄詳細信息,但是您可以插入此信息,但可以在您的應用程序中使用。