Kevin Hoffman

Folks,

I'm working on an application (game, actually) where I need to be able to create transient channels... some of the clients will start listening on and sending to a given mesh based on where the player is in the game. So, when I define in app.config the endpoint for net.p2p://ulyssesagenda/chat I'm fine because the peer mesh address of that channel never changes, and I'm only using a single instance of IChat to receive incoming messages.

What I need to be able to do is, at runtime, open an INavigation on net.p2p://ulyssesagenda/nav/galaxy1 or net.p2p://ulyssesagenda/nav/galaxy2 or whatever. In other words, I need to be able to dynamically create instances of these classes that implement the mesh interfaces, and I need to be able to rig them up to endpoints that have runtime-determined URIs.

When I try to create an instance of duplexchannel factory with an endpoint that I created myself, I get an error message that says something about the instance context not containing an instance of a UserObject, but I currently have no security enabled on any of my mesh endpoints.

Here's a look at the app.config for one of the peers:

< xml version="1.0" encoding="utf-8" >

<configuration>

<system.serviceModel>

<client>

<endpoint

name="ChatEndpoint"

address="net.p2p://ulyssesagenda/chat"

binding="netPeerTcpBinding"

bindingConfiguration="PeerBinding"

contract="UlyssesAgenda.NetworkLibrary.IChat"/>

<endpoint

name="AuthEndPoint"

address="net.p2p://ulyssesagenda/auth"

binding="netPeerTcpBinding"

bindingConfiguration="PeerBinding"

contract="UlyssesAgenda.NetworkLibrary.IAuthenticator" />

</client>

<bindings>

<netPeerTcpBinding>

<binding

name="PeerBinding"

port="8091"

maxReceivedMessageSize="2147483647" >

<security mode="None">

</security>

</binding>

</netPeerTcpBinding>

</bindings>

</system.serviceModel>

</configuration>

This stuff works just fine for the static meshes - the meshes that will be up and running while the application is running. What I need is some code to create an instance of a class like Navigation and attach it to an arbitrary mesh URL... and when the player moves out of that galaxy (or when some other event takes place), I want to be able to close the channel and dispose of the object.

If anybody has an example that they could post showing me how to create, at runtime, the configuration shown in my App.config, that would be extremely valuable.

Thanks!




Re: Windows Communication Foundation (Indigo) Dynamically opening and closing channels not defined by App.config

Kevin Hoffman

I swear this forum is good luck. No sooner than I posted the question did I get the solution working in another window.

_chat = new UlyssesAgenda.UniverseServer.NetLibImplementations.Chat();

_chatSite = new InstanceContext(_chat);

NetPeerTcpBinding binding = new NetPeerTcpBinding();

binding.Port = 8091;

binding.Security.Mode = SecurityMode.None;

binding.MaxReceivedMessageSize = 2147483647;

binding.Name = "chat1";

EndpointAddress address = new EndpointAddress("net.p2p://ulyssesagenda/chat");

_chatChannelFactory = new DuplexChannelFactory<IChatChannel>(_chatSite,

binding, address);

_chatProxy = (IChatChannel)_chatChannelFactory.CreateChannel();