Ice for .NET
The comprehensive features of the Ice platform are available to .NET developers using Ice for .NET. A native C# implementation of Ice provides compatibility with Visual C# as well as Mono, while the Common Language Runtime enables seamless support for other .NET languages such as Visual Basic.
On the strength of Microsoft's product support, .NET has quickly grown to prominence as an effective platform for developing Windows applications and Web services. As a result, Ice for .NET is an excellent platform for integrating Ice services with enterprise technologies such as ASP.NET and SOAP.
Sample Code
To illustrate how Ice is used in various language mappings, consider the following Slice interface definitions:
module Biz {
struct Item {
string sku;
int qty;
};
sequence<Item> ItemSeq;
interface Invoice {
void addItems(ItemSeq items);
void submit();
};
interface InvoiceFactory {
Invoice* create();
};
};
C#
C# code that creates an invoice using the factory is shown below:
// Create a proxy for the invoice factory object.
Ice.ObjectPrx proxy = communicator.stringToProxy("InvoiceFactory:tcp -p 9000");
// Narrow the proxy to the proper type.
Biz.InvoiceFactoryPrx factory = Biz.InvoiceFactoryPrxHelper.checkedCast(proxy);
// Use the factory to obtain a proxy for a new invoice object.
Biz.InvoicePrx invoice = factory.create();
// Add items to the invoice.
Biz.Item[] items = new Biz.Item[1];
items[0].sku = "10-6139";
items[0].qty = 3;
invoice.addItems(items);
// Submit the invoice.
invoice.submit();
Visual Basic
Here is the equivalent code in Visual Basic:
' Create a proxy for the invoice factory object.
Dim proxy As Ice.ObjectPrx = communicator.stringToProxy("InvoiceFactory:tcp -p 9000")
' Narrow the proxy to the proper type. Dim factory As Biz.InvoiceFactoryPrx = Biz.InvoiceFactoryPrxHelper.checkedCast(proxy)
' Use the factory to obtain a proxy for a new invoice object. Dim invoice As Biz.InvoicePrx = factory.create()
' Add items to the invoice.
Dim items() As Biz.Item = New Biz.Item(0) {}
items(0).sku = "10-6139"
items(0).qty = 3
invoice.addItems(items)
' Submit the invoice. invoice.submit()