本文介绍了无效的URI:无法解析主机名. W7 Home-是,W7 Starter-否.有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好!
关键是调试我的C#应用程序时遇到了错误:未处理UriFormatException.我已经创建了p2p控制台聊天.
Hi there!
The point is that debugging my C# app I faced the error: UriFormatException was unhandled. I''ve created p2p console chat.
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:
Program.cs :
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
}
}
并且调试在chatClient.Open()处停止,日志为无效的URI:无法解析主机名."
顺便说一句,应该提到的是该代码在我的Windows 7 Home Edition中可以成功运行.但是在Windows 7 Starter中,它显示了此异常.
你有同样的经历吗?
在此先感谢.
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.
推荐答案
<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>
这篇关于无效的URI:无法解析主机名. W7 Home-是,W7 Starter-否.有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!