MSDN C# example on IPCChannel compile error !

L

Lonewolf

hi all,
I realize the example on MSDN for IPCChannel has compile error in
VS2005 pro. Either I'm missing something or there's something seriously
wrong with MSDN on that section. I reproduce the MSDN code sample for
IPCchannel for server side in c# below. please help me see what I'm
missing here.

[C#]
using System;
using System.Runtime.Remoting.Channels.Ipc;
using System.Security.Permissions;

public class Server
{
[SecurityPermission(SecurityAction.Demand)]
public static void Main(string[] args)
{
// Create the server channel.
IpcChannel serverChannel =
new IpcChannel("localhost:9090");


// Register the server channel.
/****************************************************************************************************************************
The line below gives an obsolete warning when attempting to compile in
VS2005 pro.
Warning 1
'System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(System.Runtime.Remoting.Channels.IChannel)'
is obsolete: 'Use
System.Runtime.Remoting.ChannelServices.RegisterChannel(IChannel chnl,
bool ensureSecurity) instead.'

*******************************************************************************************************************************/

System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(serverChannel);


// Show the name of the channel.
Console.WriteLine("The name of the channel is {0}.",
serverChannel.ChannelName);

// Show the priority of the channel.
Console.WriteLine("The priority of the channel is {0}.",
serverChannel.ChannelPriority);

// Show the URIs associated with the channel.
System.Runtime.Remoting.Channels.ChannelDataStore channelData =
(System.Runtime.Remoting.Channels.ChannelDataStore)
serverChannel.ChannelData;
foreach (string uri in channelData.ChannelUris)
{
Console.WriteLine("The channel URI is {0}.", uri);
}

// Expose an object for remote calls.
/********************************************************************************************
The line below gives an Error
Error 2 The type or namespace name 'RemoteObject' could not be found
(are you missing a using directive or an assembly reference?)
********************************************************************************************/
System.Runtime.Remoting.RemotingConfiguration.
RegisterWellKnownServiceType(
typeof(RemoteObject), "RemoteObject.rem", <==== this
is the line of Error
System.Runtime.Remoting.WellKnownObjectMode.Singleton);

// Parse the channel's URI.
string[] urls = serverChannel.GetUrlsForUri("RemoteObject.rem");
if (urls.Length > 0)
{
string objectUrl = urls[0];
string objectUri;
string channelUri = serverChannel.Parse(objectUrl, out
objectUri);
Console.WriteLine("The object URI is {0}.", objectUri);
Console.WriteLine("The channel URI is {0}.", channelUri);
Console.WriteLine("The object URL is {0}.", objectUrl);
}

// Wait for the user prompt.
Console.WriteLine("Press ENTER to exit the server.");
Console.ReadLine();
Console.WriteLine("The server is exiting.");
}
}


sorry for the long post, but this is the only way to show the problem.
the URL where the code is taken from is
http://msdn2.microsoft.com/en-us/library/system.runtime.remoting.channels.ipc.ipcchannel.aspx


I created a C# console project, and added the ref to
system.runtoime.remoting to the project, What else am I missing here ?
the MSDN site did not mention any other assembly besides the remoting
dll. Could anyone please enlighten me here? thank you very much.
 
S

simon.dahlbacka

...at least you are missing the code for RemoteObject, (see the third
code example box on that page "The following code example shows the
remote object used by the server and the client.".)
 
W

Willy Denoyette [MVP]

| hi all,

| The line below gives an Error
| Error 2 The type or namespace name 'RemoteObject' could not be found
| (are you missing a using directive or an assembly reference?)
|
********************************************************************************************/

| I created a C# console project, and added the ref to
| system.runtoime.remoting to the project, What else am I missing here ?
| the MSDN site did not mention any other assembly besides the remoting
| dll. Could anyone please enlighten me here? thank you very much.

Did you compile the three files in the right order and with the correct
compile flags?
The RemoteObject is a class used by both the client and the server, you need
to compile this first and add a reference to it when compiling the server
and the client.
Note that IMO you better start by reading some docs. before you blindly
start to copy and past samples from MSDN, you seem to be missing some
fundamental knowledge about .NET in general, if you fail to see what above
error message means.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top