使用对等聊天应用程序作为示例的 WCF 应用程序不起作用
我使用可用的 Microsoft 聊天应用程序示例将 VB .Net 3.5 应用程序转换为使用对等 WCF。我确保复制了示例的 app.config 文件(修改了我的应用程序的名称),添加了适当的引用。我遵循了所有教程,并在我的应用程序代码中添加了适当的标签和结构。一切都运行没有任何错误,但客户端只能从自己那里获取消息,而不是从其他客户端获取消息。示例聊天应用程序在多个客户端上运行得很好。我能发现的唯一区别是示例中的服务器针对框架 2.0,但我认为这是错误的,它至少在 3.0 中构建它,否则 System.ServiceModel 引用将中断。是否需要注册该示例在幕后执行的操作,或者该示例是否是特殊的项目类型?我很困惑。我的下一步是将所有类和逻辑从我的应用程序复制到示例应用程序,但这可能需要大量工作。
这是我的客户端 App.config:
<client><endpoint name="thldmEndPoint"
address="net.p2p://thldmMesh/thldmServer"
binding="netPeerTcpBinding"
bindingConfiguration="PeerTcpConfig"
contract="THLDM_Client.IGameService"></endpoint></client>
<bindings><netPeerTcpBinding>
<binding name="PeerTcpConfig" port="0">
<security mode="None"></security>
<resolver mode="Custom">
<custom address="net.tcp://localhost/thldmServer" binding="netTcpBinding"
bindingConfiguration="TcpConfig"></custom>
</resolver>
</binding></netPeerTcpBinding>
<netTcpBinding>
<binding name="TcpConfig">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
这是我的服务器 App.config:
<services>
<service name="System.ServiceModel.PeerResolvers.CustomPeerResolverService">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/thldmServer"/>
</baseAddresses>
</host>
<endpoint address="net.tcp://localhost/thldmServer"
binding="netTcpBinding"
bindingConfiguration="TcpConfig"
contract="System.ServiceModel.PeerResolvers.IPeerResolverContract">
</endpoint>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="TcpConfig">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
提前致谢。
I converted a VB .Net 3.5 app to use peer to peer WCF using the available Microsoft example of the Chat app. I made sure that I copied the app.config file for the sample(modified the names for my app), added the appropriate references. I followed all the tutorials and added the appropriate tags and structure in my app code. Everything runs without any errors, but the clients only get messages from themselves and not from the other clients. The sample chat application does run just fine with multiple clients. The only difference I could find is that the server on the sample is targeting the framework 2.0, but I assume that is wrong and it is building it in at least 3.0 or the System.ServiceModel reference would break. Is there something that has to be registered that the sample is doing behind the scenes or is the sample a special project type? I am confused. My next step is to copy all my classes and logic from my app to the sample app, but that is likely a lot of work.
Here is my Client App.config:
<client><endpoint name="thldmEndPoint"
address="net.p2p://thldmMesh/thldmServer"
binding="netPeerTcpBinding"
bindingConfiguration="PeerTcpConfig"
contract="THLDM_Client.IGameService"></endpoint></client>
<bindings><netPeerTcpBinding>
<binding name="PeerTcpConfig" port="0">
<security mode="None"></security>
<resolver mode="Custom">
<custom address="net.tcp://localhost/thldmServer" binding="netTcpBinding"
bindingConfiguration="TcpConfig"></custom>
</resolver>
</binding></netPeerTcpBinding>
<netTcpBinding>
<binding name="TcpConfig">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
Here is my server App.config:
<services>
<service name="System.ServiceModel.PeerResolvers.CustomPeerResolverService">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/thldmServer"/>
</baseAddresses>
</host>
<endpoint address="net.tcp://localhost/thldmServer"
binding="netTcpBinding"
bindingConfiguration="TcpConfig"
contract="System.ServiceModel.PeerResolvers.IPeerResolverContract">
</endpoint>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="TcpConfig">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
Thanks ahead of time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信我已经找到答案了。我遇到了一个不冒泡的异常(由于单向操作合约),这会删除该实例。一旦关闭,就不再有任何消息可用。如果 MS 至少将这些异常放在输出堆栈上,那就太好了。现在我已经优雅地处理了错误,消息将发送给所有客户端。需要注意的一件事是,如果您使用单向合约,则不能以任何方式向客户端冒泡例外。我想我明白,因为如果 4 个对等点有异常,您会得到哪个异常(全部 4 个?)所以我想在广播消息的对等网格中,您无法获得任何类型的回复是有道理的。
I believe I figured out the answer. I had an exception that was not bubbling (due to the One-Way operation contract) and that would take down that instance. Once it was down no more messages would work. It would be nice it MS would at least put these exceptions on the output stack. Now that I handle the errors gracefully, the messages to go to all the clients. One thing to note is that if you are using a one-way contract, you cannot bubble exceptions to the client in any way. I guess I understand, since if 4 peers had exceptions, which exception would you get (all 4?) So I guess it makes sense that in a peer mesh where the messages are broadcast, that you cannot get replies of any kind.