Hello everyone. I was trying to get help with a sp...
# suitetalkapi
s
Hello everyone. I was trying to get help with a specific SOAP web service connection. I'm stuck on the first exercise of the course because the my request response is not showing under the usage log. Any idea what's happening?
b
you wont get very far without sharing what your request looks like
less ideal is the code
s
Copy code
using NetSuite.com.netsuite.webservices;
using System;
using <http://System.Net|System.Net>;
using System.Xml;

namespace NetSuite {
    /// <summary>
    /// This is the main class for the SuiteTalk course. All of the web service operations are to be added in this class.
    /// The only operations that exist initially is a simple get request.
    ///
    /// </summary>
    class SuiteTalkCourse {

        // Passport info
        const string netsuiteApplicationId = "";
        const string netsuiteEmail = "";
        const string netsuitePassword = "";
        const string netsuiteAccountNumber = "";
        const string netsuiteRoleId = "";

        // Web Serices URL info
        const string netsuiteAccountVersion = "2020_1";

        // Token Based Authentication info
        const string netsuiteConsumerKey = "";
        const string netsuiteConsumerSecret = "";
        const string netsuiteTokenId = "";
        const string netsuiteTokenSecret = "";

        // All web service operations executed against the NetSuiteService
        public NetSuiteService _service;

        // Object containing preferences that get generated in the Soap header of a request
        private Preferences _prefs;

        // Object containing search specific preferences that get generated in the Soap header of a request
        private SearchPreferences _searchPreferences;


        public SuiteTalkCourse()
        {
            /*
             * Sets the application to accept all certificates coming from a secure server.
             * NOTE: This line is only required if the network or application needs to communicate over HTTPS (SSL).
             */
            ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

            const SecurityProtocolType Tls12 = (SecurityProtocolType)0x00000c00;
            ServicePointManager.SecurityProtocol = Tls12;

            // All web service operations execute against the _service field
            _service = new NetSuiteService();

            // Added to make sure the application works regardless of the data center
            setDataCenterUrl(netsuiteAccountNumber);

            setPreferences();   // Set all preferences, search & regular
            setPassport();      // Set the Passport information for authentication
            setTokenPassport(); // Comment out the setPassport() call and uncomment this to use tokens for logging in.
        }

        [STAThread] // .Net attribute that indicates single threading. KEEP!

        static void Main(string[] args)
        {
            /*
             * Creates an instance of the class. The Constructor is executed which creates the _service field,
             * sets preferences, etc.
             */
            SuiteTalkCourse ns = new SuiteTalkCourse();

            /*
             * A try-catch block is set up with appropriate exception handling for various
             * .Net specific system and web service level exceptions.
             * As the course progresses you will find that many NetSuite web service errors are captured in
             * a status object, and do not generate exceptions.
             */
            try
            {
                /*
                 * Here is an example web service operation to get a vendor. Create new methods as needed as
                 * you go through the course. In general you will create a new method for each exercise, though
                 * some exercises build upon the code of a previous exercise. Execute your method here, as is the
                 * case with the getVendor example. Feel free to comment out existing methods so that you're
                 * executing only what supports a specific exercise.
                 */

                ns.getVendor();

                // Spacer line added for formatting.
                Console.WriteLine("");
            }
            catch (System.Web.Services.Protocols.SoapException ex) {
                // Get the fault type. It's the only child element of the detail element.
                string fault   = ex.Detail.FirstChild.Name;
                string code    = null;
                string message = null;

                // Get the list of child elements of the fault type element.
                // It should include the code and message elements
                System.Collections.IEnumerator ienum = ex.Detail.FirstChild.ChildNodes.GetEnumerator();

                while (ienum.MoveNext()) {
                    XmlNode node = (XmlNode)ienum.Current;

                    if (node.Name == "code") {
                        code = node.InnerText;
                    } else if (node.Name == "message") {
                        message = node.InnerText;
                    }
                }
                Console.WriteLine("\n***   SOAP FAULT: fault type={0} with code={1}. {2}", fault, code, message);
            }
            catch (System.Net.WebException ex) {
                Console.WriteLine("[SOAP Fault Web Exception]: {0}", ex.Message);
            }
            catch (System.InvalidOperationException ex) {
                Console.WriteLine("[SOAP Fault Invalid Operation Exception]: {0}", ex.Message);
            }
            catch (System.Exception ex) {
                Console.WriteLine("[Error]: {0}", ex.Message);
            }
        }

        /// <summary>
        /// Set the Data Center Url based on where the account is stored.
        /// </summary>
        /// <param name="accountId"></param>
        private void setDataCenterUrl(String accountId)
        {
            DataCenterUrls dataCenterUrls = _service.getDataCenterUrls(accountId).dataCenterUrls;
            String webServiceUrl = dataCenterUrls.webservicesDomain;

            _service.Url = webServiceUrl + "/services/NetSuitePort_" + netsuiteAccountVersion + "?c=" + accountId;
        }


        /// <summary>
        /// Sets the authentication information needed to connect to NetSuite
        /// </summary>
        private void setPassport() {
            // Replace text in the next lines as noted
            _service.applicationInfo = new ApplicationInfo {
                applicationId = netsuiteApplicationId
            };

            _service.passport = new Passport {
                email    = netsuiteEmail,
                password = netsuitePassword,
                account  = netsuiteAccountNumber,
                role     = new RecordRef { internalId = netsuiteRoleId }
            };

            // Display the login information in the console
            Console.WriteLine("Login info...");
            Console.WriteLine("\tEmail           : {0}", _service.passport.email);
            Console.WriteLine("\tRole Internal ID: {0}", _service.passport.role.internalId);
            Console.WriteLine("\tAccount Number  : {0}", _service.passport.account);
            Console.WriteLine("\tApplication ID  : {0}\n", _service.applicationInfo.applicationId);
        }


        /// <summary>
        /// This provides an alternative way of authentication by using tokens instead of
        /// username and password combinations
        /// </summary>
        private void setTokenPassport() {
            /* Replace text with the information generated by the integration and token records */
            string accountId      = netsuiteAccountNumber;
            string consumerKey    = netsuiteConsumerKey;
            string consumerSecret = netsuiteConsumerSecret;
            string tokenId        = netsuiteTokenId;
            string tokenSecret    = netsuiteTokenSecret;

            _service.tokenPassport = WsHelper.generateTokenPassport(accountId, consumerKey, consumerSecret, tokenId, tokenSecret);
        }


        /// <summary>
        /// This method builds the Pereferences and SearchPreferences in the SOAP header.
        /// Any preferences entered here at the request level override preferences at the
        /// company-level. Company level preferences can be set at
        /// Setup > Integration > Web Services Preferences
        /// </summary>
        private void setPreferences() {
            /* Set objects that contain request-level preferences */

            _service.preferences = new Preferences {
                // Add your Web Service Preference Settings here.
            };

            _service.searchPreferences = new SearchPreferences {
                // Add your Search Preferences here.
            };
        }


        /// <summary>
        /// Sample Get operation call
        /// </summary>
        private void getVendor() {
            RecordRef vendorRef = new RecordRef {
                internalId    = "211",
                type          = RecordType.vendor,
                typeSpecified = true
            };

            _service.get(vendorRef);
        }
    }
}
Here's the code that I downloaded from the training account.
Everytime I try to click Start without Debugging it's showing a data but it will immediately close for a second. Any ideas why?
b
first off you need to fill out those strings at the top with valid values
s
Yes, I already did that. I just removed it for security purposes.
b
eventually you will learn that a lot of the passport related stuff is deprecated
though you should get a more useful error message
s
I only have these two. But regardless of the build, I think this should work. But I don't what's happening.
b
if you get most of the passport and tokens correct, you should at least be getting entries in the Login Audit Trail
looking at your error, your code isnt even building
s
I double checked all the .NET Framework versions installed - its still not working.
Any workarounds?
b
probably want to check which version of .net the project requires and install that version
s
I already installed the required version of .net but nothing is happening and it keeps on prompting this box:
message has been deleted
b
are you sure the project is 4.5
a lot of that output looks like 4.0
s
Hi, I solved one problem. I updated the version of the .NETFramework to 4.8 - it was built successfully. The only problem remains is it's not showing on the usage log.
b
usage log is for requests that pass authentication
login audit trail is for those that fail
s
this makes me not miss .NET much