|
/* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com */
using System;
using System.Collections;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Channels.Tcp;
using Db4objects.Db4o;
using RemotingClasses;
/*
* Client test class. Creates a test object and passes it over the network
* to be stored to the database.
*/
namespace RemotingExample
{
class Program
{
// Remote test proxy
Db4oRemoteFactory factory;
public Program()
{
string url;
// Setup a client channel to our services.
url = @"tcp://LocalHost:65101/";
BinaryClientFormatterSinkProvider clientProvider =
new BinaryClientFormatterSinkProvider();
BinaryServerFormatterSinkProvider serverProvider =
new BinaryServerFormatterSinkProvider();
serverProvider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 0;
props["name"] = System.Guid.NewGuid().ToString();
props["typeFilterLevel"] = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
TcpChannel chan =
new TcpChannel(props, clientProvider, serverProvider);
ChannelServices.RegisterChannel(chan);
// Set an access to the remote proxy
factory = (Db4oRemoteFactory)RemotingServices.Connect(
typeof(Db4oRemoteFactory), url + "TestFactoryEndPoint"
);
}
// end Program
static void Main(string[] args)
{
new Program().RunTest();
}
// end Main
private void RunTest()
{
// Remote persistent class
TestValue testValue;
testValue = new TestValue();
// Modify local TestValue object
testValue.ChangeData("Test value");
// Pass testValue to the server through testServer
// and store the testValue object
IObjectContainer testServer = factory.OpenFile("test.db4o");
testServer.Set(testValue);
// Test what is stored to the database
IList result = testServer.Get(typeof(TestValue));
//TestValue test;
foreach (TestValue test in result) {
System.Console.WriteLine(test);
}
}
// end RunTest
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.