Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there!
The point is that debugging my C# app I faced the error: UriFormatException was unhandled. I've created p2p console chat.
C#
namespace PeerChannelBasic
{
    [ServiceContract(
        Namespace = "http://slickthought.net/peerchannel",
        CallbackContract = typeof(IPeerChannelChat))]
    public interface IPeerChannelChat
    {
        [OperationContract(IsOneWay = true)]
        void Logon(string name);

        [OperationContract(IsOneWay = true)]
        void Chat(string name, string message);

        [OperationContract(IsOneWay = true)]
        void Logoff(string name);
    }

    public interface IPeerChannelChatClient : IPeerChannelChat, IClientChannel { }
}


Program.cs :

C#
namespace PeerChannelBasic
{
    class Program : IPeerChannelChat
    {
        static void Main(string[] args)
        {
            Console.Write("Enter your name: ");
            string member = Console.ReadLine();

            InstanceContext context = new InstanceContext(new Program());

            DuplexChannelFactory<IPeerChannelChatClient> factory = new DuplexChannelFactory<IPeerChannelChatClient>
                (context, "ChatChannel");
            IPeerChannelChatClient chatClient = factory.CreateChannel();

            IOnlineStatus onlineStatus = chatClient.GetProperty<IOnlineStatus>();
            onlineStatus.Online += new EventHandler(onlineStatus_Online);
            onlineStatus.Offline += new EventHandler(onlineStatus_Offline);

            Console.Write("Opening chat client... ");
            chatClient.Open(); // debug stops
            Console.WriteLine("OPENED");

            chatClient.Logon(member);

            while (true)
            {
                Console.Write("Say: ");
                string message = Console.ReadLine();
                if (message.ToUpper() == "QUIT") break;

                chatClient.Chat(member, message);
            }

            chatClient.Logoff(member);
            chatClient.Close();
            factory.Close();
        }

        #region OnlineStatus
        static void onlineStatus_Offline(object sender, EventArgs e)
        {
            Console.WriteLine("<<<- chatClient is OFFLINE");
        }

        static void onlineStatus_Online(object sender, EventArgs e)
        {
            Console.WriteLine("<<<- chatClient is ONLINE");
        }
        #endregion

        #region IPeerChannelChat Members
        public void Logon(string name)
        {
            Console.WriteLine("<<<-{0} JOINED", name.ToUpper());
        }

        public void Chat(string name, string message)
        {
            Console.WriteLine("{0} SAYS ---> {1}", name.ToUpper(), message);
        }

        public void Logoff(string name)
        {
            Console.WriteLine("<<<-{0} EXITED", name.ToUpper());
        }
        #endregion
    }
}


And debugging stops at chatClient.Open() with logs "Invalid URI: The hostname could not be parsed."

By the way, it should be mentioned that this code successfully works in my Windows 7 Home Edition. But in Windows 7 Starter it shows this exception.

Have you got the same experience?
Thanks in advance.
Posted
Updated 1-Jan-12 1:40am
v2
Comments
Shmuel Zang 1-Jan-12 2:57am    
Can you post the endpoint's configuration?

1 solution

As about the config file with endpoint ChatChannel:
C#
<configuration>
  
    <system.servicemodel>

        <client>
            <!-- chat instance participating in the mesh -->
          <endpoint name="ChatChannel">
              address = "net.p2p://chatMesh/ServiceModelSamples/Chat"
              binding = "netPeerTcpBinding"
              bindingConfiguration = "BindingDefault"
              contract = "PeerChannelBasic.IPeerChannelChat">
          </endpoint>
        </client>
      
        <bindings>
          <netpeertcpbinding>
            <binding name="BindingDefault" port="0">
              <security mode="None" />
              <resolver mode="Auto" />
            </binding>
          </netpeertcpbinding>
          
          <nettcpbinding>
            <!-- You can change security mode to enable security -->
            <binding name="Binding3">
              <security mode="None" />
            </binding>
          </nettcpbinding>
        </bindings>
    
     </system.servicemodel>
  
</configuration>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900