Building an Application with Microsoft .NET
This section provides details on how to use the Microsoft .NET platform to build a SOAP web services application. You can also see Downloading Sample Applications for a .NET sample currently available.
When building an application with Microsoft .NET, you should use Visual Studio .NET since it provides an integrated development environment to build and debug your Web service applications. Alternatively, you can download and install the Microsoft .NET Framework SDK. However, this only provides you with the SDK and does NOT provide an integrated IDE.
All code samples in this section use the C# language, however these steps are similar for all other languages supported by Microsoft .NET. These languages include Visual Basic, Visual J#, and C++.
To use Microsoft .NET with NetSuite SOAP web services:
-
Install the Microsoft .NET framework.
Install Microsoft .NET Framework 4.6, which includes the .NET framework SDK (PREFERRED), or the Microsoft .NET Framework SDK version 1.1 (NOT preferred).
-
Use the .NET framework SDK to automatically generate the client proxy code
If using Microsoft .NET Framework (PREFERRED):
-
Start Microsoft .NET Framework 4.6.
-
Create a new project and choose a template, for example, Console Application.
-
After the project has been created, add a Web reference.
The Add Web Reference option may be available in the Project menu. If not, select Add Service Reference, click the Advanced button, and click the Add Web Reference button.
-
In the Add Web Reference dialog, enter the SOAP WSDL URL and click the Go icon.
A URL for the latest SOAP WSDL is: https://webservices.netsuite.com/wsdl/v2023_1_0/netsuite.wsdl
Note:Although the material in this guide pertains to the latest NetSuite WSDL, we continue to support endpoints released prior to this version.
-
Visual Studio inspects the WSDL and displays a summary of the available operations. If security warnings are displayed, click Yes as many times as necessary to continue this process.
-
After the summary is displayed, click the Add Reference button to generate the classes.
When this process is complete, com.netsuite.webservices is listed under Web References in the Solution Explorer.
-
To view all generated proxy classes, do one of the following:
-
Enable the Show All Files option in the Project menu
-
(If the above option is not available), right-click the com.netsuite.webservices listing in the Solution Explorer and choose View in Object Browser.
-
If using only the Microsoft .NET Framework SDK (NOT preferred):
-
Locate the wsdl.exe file under the Microsoft .NET Framework SDK installation and add it to your system path.
-
Open a command prompt, and type the following to generate the proxy classes:
wsdl /language:<language> <url>
Where <language> is your preferred language and <url> is the URL for the NetSuite WSDL.
For example, generate the proxy classes in C# as follows:
C:\project>wsdl /language:cs https://webservices.netsuite.com/wsdl/ v2017_1_0/netsuite.wsdl
A C# file called NetSuiteService.cs is generated.
-
Compile the source code for your proxy into a .NET Assembly using the .NET Framework C# compiler or any other supported compiler.
-
Locate the csc.exe file under the Microsoft .NET Framework SDK installation and add it to your system path.
csc.exe /out: NetSuiteService.dll /target:library reference:system.xml.serialization.dll / reference:system.web.services.dll NetSuiteService.cs
-
-
Implement your application by writing your business logic using the generated .NET proxy classes.
Note that the following code snippets are shown in C#.
-
Allow the use of objects from the newly created namespace without having to qualify them.
using <namespace>.com.netsuite.webservices;
-
Instantiate the NetSuite service.
NetSuiteService service = new NetSuiteService();
-
Enable support for multiple cookie management.
service.CookieContainer = new CookieContainer();
-
Create a valid session by populating the Passport object.
//invoke the login operation Passport passport = new Passport(); passport.account = "TSTDRV96"; passport.email = "username@netsuite.com"; RecordRef role = new RecordRef(); role.internalId = "3"; passport.role = role; passport.password = "<SOAP web services password>"; Status status = service.login( passport ).status;
-
Implement your business logic. For example, create a new customer in NetSuite.
Customer cust = new Customer(); cust.entityID( "XYZ Inc" ); WriteResponse response = service.add( cust );
-
Logout to invalidate the current session.
-
service.logout();