Sunday, October 21, 2018

Switching WSDL versions in C#

Many Web Services programmers will need to test some scenarios in different WSDL versions (e.g. 2010.2, 2011.1) against Release Preview, Sandbox or Production account.  Below is a simple walkthrough on how to do this in C#:
 
 
 
1. Add a Web Reference in your C# Project.  Use 2011.1 WSDL for this example and name the Web Reference as "com.netsuite.production_2011_1.webservices".
 
2. Add the following line in the Namespace section:
 
     using SuiteTalkFromScratch1.com.netsuite.production_2011_1.webservices;
 
3. After instantiating a NetSuiteService object, assign this value into it:
 
     _ws = new global::SuiteTalkFromScratch1.com.netsuite.production_2011_1.webservices.NetSuiteService();
 
 
A working example (with a login operation) is as follows:
 
 
 
 
using System;
using System.Net;
using System.Web.Services.Protocols;
using SuiteTalkFromScratch1.com.netsuite.production_2011_1.webservices;


namespace SuiteTalkFromScratch1
{
    class MySuiteTalk
    {
        private NetSuiteService _ws;
        private Preferences _prefs = new Preferences();


        public MySuiteTalk() {
            _ws = new global::SuiteTalkFromScratch1.com.netsuite.production_2011_1.webservices.NetSuiteService();


            Passport passport = new Passport();
            RecordRef role = new RecordRef();
            role.internalId = "3";
            passport.email = "
noemail@nodomain.com";
            passport.password = "thepassword01";
            passport.account = "TSTDRV10101";

            try {
                _ws.login(passport);
                Console.WriteLine("Congratulations! You are logged in.\n\n");
            } catch (SoapException soapEx) {
                Console.WriteLine("SoapException (after Logout):\n" + soapEx.Message + "\n\n\n");
            }
        }


        static void Main(string[] args) {
            MySuiteTalk suiteTalk = new MySuiteTalk();
        }
    }
}

No comments:

Post a Comment