• : 1-877-596-8218
  • : sales@aecc.ca
# # #

NS SuiteTalk Part 2 – Setup Login to NS Using Web Service.

To start building a Java Application with SuiteTalk Web Service, Install the Java environment and the Apache Axis frame work and Apache Axis patch from NetSuite Website. You can easily find the tutorial or instruction for these steps in NetSuite Help Center.

Now, when you have finished all necessary configurations and ready to build a Java application using SuiteTalk Web Service.

The first steps when building the application are to Location the NS service, enable multiple cookie management support, and get the NetSuite port. As shown in the codes below:

NetSuiteServiceLocator service = new NetSuiteServiceLocator();
service.setNetSuitePortEndpointAddress(" https://webservices.netsuite.com/services/NetSuitePort_2016_1 ");
NetSuitePortType port = service.getNetSuitePort();

The input parameter of the function setNetSuitePortEndpointAddress() is the account’s Host Data Center URL. NetSuite hosts customers’ accounts in different data center with different URLs. the URL must be the actual URL which hosting the account with the account ID provided later.

Alternatively, one can use the function getDataCenterUrls() to auto discover the correct URL.
The following codes demonstrate the how we can achieve this.

public void init() throws IOException, ServiceException  {
   properties = new Properties();
   properties.load(new FileInputStream("nsclient.properties"));
   // Locate the NetSuite web service.
   NetSuiteServiceLocator service = new DataCenterAwareNetSuiteServiceLocator(properties.getProperty("login.acct"));
   //Enabling client cookies
   //get the service port (to the correct datacenter)
   port = service.getNetSuitePort(new URL(properties.getProperty("ws.url")));
   //client timeout (2 hours)
   ((NetSuiteBindingStub) port).setTimeout(1000 * 60 * 60 * 2);

public class DataCenterAwareNetSuiteServiceLocator extends NetSuiteServiceLocator {
   private String account;

   public DataCenterAwareNetSuiteServiceLocator(String account) {
       this.account = account;
   public NetSuitePortType getNetSuitePort(URL defaultWsDomainURL) {
       try {
           NetSuitePortType port = super.getNetSuitePort(defaultWsDomainURL);
           //WebServices domain for current account
           DataCenterUrls urls = port.getDataCenterUrls(account).getDataCenterUrls();
           String wsDomain = urls.getWebservicesDomain();
           //Url appropriate for the specific account
           return super.getNetSuitePort(new URL(wsDomain.concat(defaultWsDomainURL.getPath())));
       } catch (Exception e) {
           throw new RuntimeException(e);

The function init() reads the input parameters from a file called “nsclient.properties”.
When locate the NetSuite Web Service by calling DataCenterAwareNetSuiteServiceLocator() class, the constructor of this class accept the account ID as the input parameter. And its member function getNetSuitePort() will return the correct port with the actual URL for this account.

The next step is to set SOAP Header Element.
After 2015.2, all requests must include either the application ID or the TBA authentication details. In our case, we must put the application ID into the header of each SOAP request.

//The application always needs to be part of the request
SOAPHeaderElement applicationHeader = createApplicationIdHeaders();
((Stub) port).setHeader(applicationHeader);

private SOAPHeaderElement createApplicationIdHeaders() throws UnsupportedEncodingException, SOAPException {
   ApplicationInfo applicationInfo = new ApplicationInfo();
   SOAPHeaderElement prefHeader = new SOAPHeaderElement("urn:messages_" + CURRENT_VERSION + ".platform.webservices.netsuite.com", "applicationInfo", applicationInfo);
   return prefHeader;