Introduction

.NET/Link

Welcome to .NET/Link, a product that integrates the Wolfram Language and Microsoft's .NET platform. .NET/Link lets you call .NET from the Wolfram Language in a completely transparent way, and allows you to use and control the Wolfram Language kernel from a .NET program. For Wolfram Language users, .NET/Link makes the entire .NET world an automatic extension to the Wolfram Language environment. For .NET programmers, .NET/Link turns the Wolfram Language into a scripting shell that lets you experiment with, build, and test .NET classes a line at a time. It also makes .NET an ideal environment for writing programs that use the computational services of the Wolfram Language.

.NET/Link's most unique feature is that it lets you load arbitrary .NET types into the Wolfram Language and then create .NET objects and call methods, properties, and so on, directly from the Wolfram Language. Thus, you can use the Wolfram Language to "script" the functionality of an arbitrary .NET programin effect, write a .NET program in the Wolfram Language. Essentially anything you can do from .NET, you can now do from the Wolfram Language, perhaps even more easily because you are working in a true interpreted environment.

.NET/Link also lets you do some very useful things that do not appear to directly involve the .NET runtime. These include calling C-style DLL functions directly from the Wolfram Language, and creating and scripting COM objects, much like Visual Basic can do.

.NET/Link is designed for end-users and developers alike. The same features that let Wolfram Language users transparently call any .NET method also let developers create sophisticated commercial add-ons to the Wolfram Language. Programmers who want to write custom front ends for the Wolfram Language or use the Wolfram Language as a computational engine for another program will find using .NET with .NET/Link is easier than using the traditional Wolfram Symbolic Transfer Protocol (WSTP) interface from C or C++.

Finally, .NET/Link comes with full source code. You can examine the code to supplement the documentation, get tips for your own programs, better understand how to use advanced features, or just see how it works.

Some familiarity with both the .NET Framework and the Wolfram Language is assumed in this tutorial. In Part 2, which covers writing .NET programs that call the Wolfram Language, major examples are generally provided in both C# and Visual Basic .NET versions, although overall the documentation is perhaps slightly more C#-centric. Naturally, when writing .NET programs that use .NET/Link, you can use any .NET-aware language, not just C# and Visual Basic .NET.

"Calling .NET from the Wolfram Language" shows how you use .NET/Link to call .NET from the Wolfram Language and "Calling the Wolfram Language from .NET" shows how to call the Wolfram Language from .NET.

What Is .NET?

.NET is a new development platform for Windows programming. It replaces essentially everything that came before it, including an entire alphabet soup of programming technologies such as MFC, COM, ActiveX, ATL, ASP, ADO, and many others. Although Microsoft emphasizes XML Web Services in conjunction with .NET, XML Web Services are only a small part of the .NET platform, and the success of .NET is not dependent on the widespread adoption of XML Web Services.

.NET represents the future of Windows programming, and Microsoft is rapidly shifting more and more of its technology and products to a .NET foundation.

At the core of .NET is a runtime engine, similar to that used by Java, that loads and executes programs compiled into special bytecodes that the runtime understands. This runtime is called the Common Language Runtime (CLR), but we will often refer to it as the .NET runtime. A key feature of this system is that many languages can be compiled into CLR bytecodes and executed by the runtime. This means that .NET is language neutral, supporting any programming language for which a .NET compiler is available. Microsoft provides compilers for C#, Visual Basic .NET, JScript, Visual J# .NET, and C++ With Managed Extensions. Many other compilers exist, including ones for Fortran, Perl, Python, Eiffel, and COBOL. You can even create a class in one .NET language, say Visual Basic .NET, and subclass it in another language.

Although .NET is language neutral, probably the two most important .NET languages are Visual Basic .NET, a modification of the Visual Basic language, and C#, a new language that is similar in many ways to Java.

What Is WSTP?

The Wolfram Symbolic Transfer Protocol (WSTP) is Wolfram Research's protocol for sending data and commands back and forth between the Wolfram Language and other programs. WSTP is the underlying glue that lets .NET and the Wolfram Language talk to each other. When calling .NET from the Wolfram Language, .NET/Link completely hides the low-level details of the WSTP communication, allowing Wolfram Language programmers to load and use .NET classes as if they were part of the Wolfram Language environment itself. When writing .NET programs that call the Wolfram Language, .NET/Link provides a higher-level layer of functionality than the traditional C WSTP programming interface.

How Does .NET/Link Compare to J/Link?

J/Link is an existing Wolfram Research product that integrates Java and the Wolfram Language in almost exactly the same way that .NET/Link integrates .NET and the Wolfram Language. You can use J/Link to do many of the same things you can do with .NET/Link and vice versa. Because it is based on Java, J/Link has the advantage of being cross platform. If you want to write programs that run on every Wolfram Language platform, you should use J/Link. On the other hand, .NET integrates more tightly with the Windows operating system than Java does, so if you want to do Windows-specific things, or you want a very native Windows look and feel, you should use .NET/Link. On Windows, .NET/Link also does some things that J/Link cannot, such as allowing you to call C-style DLL functions directly from the Wolfram Language, or controlling COM objects.

.NET/Link and J/Link provide a very similar programming model. Familiarity with one will be very helpful when working with the other.