To get samples and instructions for installing them
Do one or more of the following:
On the Help menu, click Samples.
The Readme displays information about samples.
Visit the Visual Studio 2008 Samples Web site. The most recent versions of samples are available there.
Locate samples on the computer on which Visual Studio is installed. By default, samples and a Readme file are installed in drive:\Program Files\Microsoft Visual Studio 9.0\Samples\lcid. For Express editions of Visual Studio, all samples are located online.
For more information, see
Note: |
---|
Active nodes in the mesh publish their mesh names so that others can find them. A mesh adjusts to changing membership, it has adaptable connectivity in an environment in which nodes are constantly joining and leaving the mesh, and it is dynamically optimized to adapt to traffic patterns. |
Active nodes in the mesh publish their mesh names so that others can find them. A mesh adjusts to changing membership, it has adaptable connectivity in an environment in which nodes are constantly joining and leaving the mesh, and it is dynamically optimized based on traffic patterns.
A peer node is an endpoint in a mesh. A single application can have multiple peer nodes that participate in different meshes.
A peer resolver is responsible for resolving a mesh ID to the endpoint addresses of the nodes in the mesh. A peer node uses these addresses to connect to other nodes in the mesh. This enables messages to be propagated throughout the mesh.
Chat is a Windows Forms application. Each instance of a Chat application creates an IDuplexChannel that has the same endpoint address. Because all instances of a Chat application use the same address, a message that is sent by one instance of the application is received by all other instances on its peer channel.
The Chat application defines and implements the IChat duplex contract. The IChat contract allows for only one-way operations because the ServiceModel does not support the single-request/multiple-response paradigm. (In a multiparty channel, a single request that is sent to the mesh can generate multiple responses.)
This sample implements a static Main function to create an IClientChannel with the IChat duplex contract. The function uses the endpoint that is specified in the configuration file.
All Chat instances must use the same endpoint address to ensure that the messages sent by one instance are received by all other instances.
Chat instances in this sample locate each other either by using a custom resolver or by using the default peer resolver (PNRP). Note that PNRP is not available on Windows Server 2003. Therefore, a custom resolver must be used to run this sample on a system that is running Windows Server 2003. By default, this sample is set up to use a custom resolver. Whether a custom resolver or the default resolver is used is determined by the chat endpoint defined in the following configuration file. To switch to the default peer resolver (PNRP), replace BindingCustomResolver with BindingDefault under bindingConfiguration in the sample's configuration file.
<!-- Chat instance participating in the mesh. --> <endpoint name="ChatEndpoint" address="net.p2p://chatMesh/ServiceModelSamples/Chat" binding="netPeerTcpBinding" bindingConfiguration="BindingCustomResolver" contract="Microsoft.ServiceModel.Samples.IChat"> </endpoint> |
To enable the peer node to communicate with the Peer Channel Custom Peer Resolver service, the client-side configuration of the Peer Channel Custom Peer Resolver is defined in the configuration file.
<!-- Client used to communicate with the custom resolver service. --> <client> <endpoint configurationName="CustomPeerResolverEndpoint" address="net.tcp://localhost/ServiceModelsamples/peerResolverService" binding="netTcpBinding" bindingConfiguration="Binding3" contract="Microsoft.ServiceModel.SamplesICustomPeerResolver"> </endpoint> </client> |
The address identifies the address of the resolver service. If the resolver service is running on a remote computer, replace localhost with a qualified domain name.
The sample also demonstrates how to retrieve the peer node from IClientChannel and how to register for online and offline events by using IOnlineStatus. An online event is initiated when the peer node is connected to at least one other peer node in the mesh. An offline event is initiated when the peer node is no longer connected to any other peer node in the mesh.
Currently, metadata cannot be generated because a peer channel is not integrated with the service metadata utility (Svcutil.exe).
When you run the sample, the chat messages sent by a Chat instance are displayed in the console windows of other Chat instances. Press the Q key followed by ENTER in each console window to close the instance.
Note: |
---|
The sample currently does not handle all possible exceptions that the infrastructure may throw. If you are using these samples in a commercial or production environment, follow the appropriate exception-handling best practices. |